Class: Rhino::Ruby::AccessBase

Inherits:
Object
  • Object
show all
Defined in:
lib/rhino/ruby/access.rb

Direct Known Subclasses

AttributeAccess, DefaultAccess

Instance Method Summary collapse

Instance Method Details

#get(object, name, scope) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/rhino/ruby/access.rb', line 20

def get(object, name, scope)
  # try [](name) method :
  if object.respond_to?(:'[]') && object.method(:'[]').arity == 1
    value = begin
      object[name]
    rescue LocalJumpError
      nil
    end unless internal?(name)
    return Rhino.to_javascript(value, scope) unless value.nil?
  end
  yield
end

#has(object, name, scope) ⇒ Object



9
10
11
12
13
14
15
16
17
18
# File 'lib/rhino/ruby/access.rb', line 9

def has(object, name, scope)
  # try [](name) method :
  if object.respond_to?(:'[]') && object.method(:'[]').arity == 1
    unless internal?(name)
      value = object.[](name) { return true }
      return true unless value.nil?
    end
  end
  yield
end

#put(object, name, value) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
# File 'lib/rhino/ruby/access.rb', line 33

def put(object, name, value)
  # try []=(name, value) method :
  if object.respond_to?(:'[]=') && object.method(:'[]=').arity == 2
    rb_value = Rhino.to_ruby(value)
    begin
      return object[name] = rb_value
    rescue LocalJumpError
    end unless internal?(name)
  end
  yield
end