Class: UnboundMethod

Inherits:
Object show all
Defined in:
opal/opal/corelib/method.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source, owner, method, name) ⇒ UnboundMethod

Returns a new instance of UnboundMethod



58
59
60
61
62
63
# File 'opal/opal/corelib/method.rb', line 58

def initialize(source, owner, method, name)
  @source = source
  @owner  = owner
  @method = method
  @name   = name
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name



56
57
58
# File 'opal/opal/corelib/method.rb', line 56

def name
  @name
end

#ownerObject (readonly)

Returns the value of attribute owner



56
57
58
# File 'opal/opal/corelib/method.rb', line 56

def owner
  @owner
end

#sourceObject (readonly)

Returns the value of attribute source



56
57
58
# File 'opal/opal/corelib/method.rb', line 56

def source
  @source
end

Instance Method Details

#arityObject



65
66
67
# File 'opal/opal/corelib/method.rb', line 65

def arity
  @method.arity
end

#bind(object) ⇒ Object



81
82
83
84
85
86
87
88
89
90
# File 'opal/opal/corelib/method.rb', line 81

def bind(object)
  %x{
    if (#{@owner}.$$is_module || Opal.is_a(#{object}, #{@owner})) {
      return #{Method.new(object, @owner, @method, @name)};
    }
    else {
      #{raise TypeError, "can't bind singleton method to a different class (expected #{object}.kind_of?(#{@owner} to be true)"};
    }
  }
end

#commentsObject



77
78
79
# File 'opal/opal/corelib/method.rb', line 77

def comments
  `#{@method}.$$comments` || []
end

#inspectObject



92
93
94
# File 'opal/opal/corelib/method.rb', line 92

def inspect
  "#<#{self.class}: #{@source}##{@name} (defined in #{@owner} in #{source_location.join(':')})>"
end

#parametersObject



69
70
71
# File 'opal/opal/corelib/method.rb', line 69

def parameters
  `#{@method}.$$parameters`
end

#source_locationObject



73
74
75
# File 'opal/opal/corelib/method.rb', line 73

def source_location
  `#{@method}.$$source_location` || ['(eval)', 0]
end