Skip to content

Commit

Permalink
Add named item support to Native::Array
Browse files Browse the repository at this point in the history
  • Loading branch information
meh committed Sep 22, 2013
1 parent c0546ba commit 9f6483c
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions corelib/native.rb
Expand Up @@ -67,6 +67,7 @@ def initialize(native, options = {}, &block)
super(native)

@get = options[:get] || options[:access]
@named = options[:named]
@set = options[:set] || options[:access]
@length = options[:length] || :length
@block = block
Expand All @@ -92,13 +93,15 @@ def each(&block)
end

def [](index)
result = if @get
`#@native[#@get](#{index})`
else
`#@native[#{index}]`
result = case index
when String, Symbol
@named ? `#@native.#@named(#{index})` : `#@native[#{index}]`

when Integer
@get ? `#@native.#@get(#{index})` : `#@native[#{index}]`
end

unless index > length
if result
if @block
@block.call(result)
else
Expand Down

0 comments on commit 9f6483c

Please sign in to comment.