Class: Nashorn::Ruby::DefaultAccess

Inherits:
AccessBase show all
Defined in:
lib/nashorn/ruby/default_access.rb

Instance Method Summary collapse

Methods inherited from AccessBase

#get_slot, #has_slot, #set_slot

Instance Method Details

#get(object, name) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/nashorn/ruby/default_access.rb', line 13

def get(object, name)
  if object.respond_to?(name_s = name.to_s)
    method = object.method(name_s)
    if method.arity == 0
      return Nashorn.to_js(method.call)
    else
      return Function.wrap(method.unbind)
    end
  elsif object.respond_to?(:"#{name}=")
    return nil
  end
  super
end

#has(object, name) ⇒ Object



5
6
7
8
9
10
11
# File 'lib/nashorn/ruby/default_access.rb', line 5

def has(object, name)
  if object.respond_to?(name.to_s) ||
     object.respond_to?(:"#{name}=")
    return true
  end
  super
end

#set(object, name, value) ⇒ Object Also known as: put



27
28
29
30
31
32
# File 'lib/nashorn/ruby/default_access.rb', line 27

def set(object, name, value)
  if object.respond_to?(set_name = :"#{name}=")
    return object.send(set_name, Nashorn.to_rb(value))
  end
  super
end