Skip to content

How can I refer to self? #61

@ledsun

Description

@ledsun

Tutorial sample fast_blank is

class String
  def blank?(string)
    char *s = string
    int i = 0
    int a = string.size

    while i < a do
      return false if s[i] != ' '
      i += 1
    end

    return true
  end
end

This code define String#blank?(string) method.
But I think the fast_blank evaluates value of self, not argument.
I tried below:

class String
  def blank?
    char *s = self
  end
end

I got error below:

~ rubex fast_blank.rubex

PARSE ERROR:
Line:     char *s = self
Location: fast_blank.rubex:3
Error:

parse error on value "self" (kSELF)
Traceback (most recent call last):
	7: from /Users/shigerunakajima/rubex/bin/rubex:7:in `<main>'
	6: from /usr/local/lib/ruby/gems/2.5.0/gems/thor-0.20.0/lib/thor/base.rb:466:in `start'
	5: from /usr/local/lib/ruby/gems/2.5.0/gems/thor-0.20.0/lib/thor.rb:387:in `dispatch'
	4: from /usr/local/lib/ruby/gems/2.5.0/gems/thor-0.20.0/lib/thor/invocation.rb:126:in `invoke_command'
	3: from /usr/local/lib/ruby/gems/2.5.0/gems/thor-0.20.0/lib/thor/command.rb:27:in `run'
	2: from /Users/shigerunakajima/rubex/lib/rubex/cli.rb:21:in `generate'
	1: from /Users/shigerunakajima/rubex/lib/rubex/compiler.rb:48:in `compile'
/Users/shigerunakajima/rubex/lib/rubex/compiler.rb:105:in `generate_code': Must be a Rubex::AST::Node::MainNode, not NilClass (RuntimeError)

Tried version is 'bf5ee9365e1b93ae58c97827c1a6ef6c04cb5f33' of the mater branch.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions