Class: Method

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(receiver, owner, method, name) ⇒ Method

Returns a new instance of Method.



4
5
6
7
8
9
# File 'opal/opal/corelib/method.rb', line 4

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

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



2
3
4
# File 'opal/opal/corelib/method.rb', line 2

def name
  @name
end

#ownerObject (readonly)

Returns the value of attribute owner.



2
3
4
# File 'opal/opal/corelib/method.rb', line 2

def owner
  @owner
end

#receiverObject (readonly)

Returns the value of attribute receiver.



2
3
4
# File 'opal/opal/corelib/method.rb', line 2

def receiver
  @receiver
end

Instance Method Details

#<<(other) ⇒ Object



46
47
48
# File 'opal/opal/corelib/method.rb', line 46

def <<(other)
  @method << other
end

#>>(other) ⇒ Object



42
43
44
# File 'opal/opal/corelib/method.rb', line 42

def >>(other)
  @method >> other
end

#__marshal__(buffer) ⇒ Object

Raises:



101
102
103
# File 'opal/opal/corelib/marshal/write_buffer.rb', line 101

def __marshal__(buffer)
  raise TypeError, "no _dump_data is defined for class #{self.class}"
end

#arityObject



11
12
13
# File 'opal/opal/corelib/method.rb', line 11

def arity
  @method.arity
end

#call(*args, &block) ⇒ Object Also known as: [], ===



27
28
29
30
31
32
33
# File 'opal/opal/corelib/method.rb', line 27

def call(*args, &block)
  %x{
    #{@method}.$$p = block;

    return #{@method}.apply(#{@receiver}, args);
  }
end

#commentsObject



23
24
25
# File 'opal/opal/corelib/method.rb', line 23

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

#curry(arity = undefined) ⇒ Object



35
36
37
# File 'opal/opal/corelib/method.rb', line 35

def curry(arity = undefined)
  @method.curry(arity)
end

#inspectObject



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

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

#parametersObject



15
16
17
# File 'opal/opal/corelib/method.rb', line 15

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

#source_locationObject



19
20
21
# File 'opal/opal/corelib/method.rb', line 19

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

#to_procObject



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

def to_proc
  %x{
    var proc = self.$call.bind(self);
    proc.$$unbound = #{@method};
    proc.$$is_lambda = true;
    proc.$$arity = #{@method}.$$arity;
    proc.$$parameters = #{@method}.$$parameters;
    return proc;
  }
end

#unbindObject



50
51
52
# File 'opal/opal/corelib/method.rb', line 50

def unbind
  UnboundMethod.new(@receiver.class, @owner, @method, @name)
end