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.



75
76
77
78
79
80
81
# File 'opal/opal/corelib/method.rb', line 75

def initialize(source, owner, method, name)
  @source = source
  @owner  = owner
  @method = method
  @name   = name
  `self.$$method = method`
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

#ownerObject (readonly)

Returns the value of attribute owner.



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

def owner
  @owner
end

#sourceObject (readonly)

Returns the value of attribute source.



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

def source
  @source
end

Instance Method Details

#arityObject



83
84
85
# File 'opal/opal/corelib/method.rb', line 83

def arity
  @method.arity
end

#bind(object) ⇒ Object



99
100
101
102
103
104
105
106
107
108
# File 'opal/opal/corelib/method.rb', line 99

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

#bind_call(object, *args, &block) ⇒ Object



110
111
112
# File 'opal/opal/corelib/method.rb', line 110

def bind_call(object, *args, &block)
  bind(object).call(*args, &block)
end

#commentsObject



95
96
97
# File 'opal/opal/corelib/method.rb', line 95

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

#inspectObject



114
115
116
# File 'opal/opal/corelib/method.rb', line 114

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

#parametersObject



87
88
89
# File 'opal/opal/corelib/method.rb', line 87

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

#source_locationObject



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

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