Class: V8::Access

Inherits:
Object show all
Defined in:
lib/v8/access.rb

Instance Method Summary collapse

Instance Method Details

#get(obj, name, &dontintercept) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
# File 'lib/v8/access.rb', line 4

def get(obj, name, &dontintercept)
  methods = accessible_methods(obj)
  if methods.include?(name)
    method = obj.method(name)
    method.arity == 0 ? method.call : method.unbind
  elsif obj.respond_to?(:[]) && !special?(name)
    obj.send(:[], name, &dontintercept)
  else
    yield
  end
end

#iget(obj, index, &dontintercept) ⇒ Object



16
17
18
19
20
21
22
# File 'lib/v8/access.rb', line 16

def iget(obj, index, &dontintercept)
  if obj.respond_to?(:[])
    obj.send(:[], index, &dontintercept)
  else
    yield
  end
end

#indices(obj) ⇒ Object



70
71
72
# File 'lib/v8/access.rb', line 70

def indices(obj)
  obj.respond_to?(:length) ? (0..obj.length).to_a : yield
end

#iquery(obj, index, attributes) ⇒ Object



55
56
57
58
59
60
61
62
63
64
# File 'lib/v8/access.rb', line 55

def iquery(obj, index, attributes)
  if obj.respond_to?(:[])
    attributes.dont_delete
    unless obj.respond_to?(:[]=)
      attributes.read_only
    end
  else
    yield
  end
end

#iset(obj, index, value, &dontintercept) ⇒ Object



36
37
38
39
40
41
42
# File 'lib/v8/access.rb', line 36

def iset(obj, index, value, &dontintercept)
  if obj.respond_to?(:[]=)
    obj.send(:[]=, index, value, &dontintercept)
  else
    yield
  end
end

#names(obj) ⇒ Object



66
67
68
# File 'lib/v8/access.rb', line 66

def names(obj)
  accessible_methods(obj)
end

#query(obj, name, attributes) ⇒ Object



44
45
46
47
48
49
50
51
52
53
# File 'lib/v8/access.rb', line 44

def query(obj, name, attributes)
  if obj.respond_to?(name)
    attributes.dont_delete
    unless obj.respond_to?(name + "=")
      attributes.read_only
    end
  else
    yield
  end
end

#set(obj, name, value, &dontintercept) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
# File 'lib/v8/access.rb', line 24

def set(obj, name, value, &dontintercept)
  setter = name + "="
  methods = accessible_methods(obj, true)
  if methods.include?(setter)
    obj.send(setter, value)
  elsif obj.respond_to?(:[]=) && !special?(name)
    obj.send(:[]=, name, value, &dontintercept)
  else
    yield
  end
end