I'm trying to load a ruby library on my mac. The "sudo gem install rb-blink1" works fine, but when I go to load it:
require 'blink1'
SyntaxError: /Library/Ruby/Gems/1.8/gems/rb-blink1-0.0.6/lib/blink1.rb:136: odd number list for Hash
id: i,
^
/Library/Ruby/Gems/1.8/gems/rb-blink1-0.0.6/lib/blink1.rb:136: syntax error, unexpected ':', expecting '}'
id: i,
^
/Library/Ruby/Gems/1.8/gems/rb-blink1-0.0.6/lib/blink1.rb:137: syntax error, unexpected ':', expecting '='
serial: cached_serial(i),
^
/Library/Ruby/Gems/1.8/gems/rb-blink1-0.0.6/lib/blink1.rb:137: syntax error, unexpected ',', expecting kEND
/Library/Ruby/Gems/1.8/gems/rb-blink1-0.0.6/lib/blink1.rb:139: syntax error, unexpected '}', expecting kEND
Here's the function from the original library:
def self.list
count = enumerate_vid_pid(vendor_id, product_id)
i = 0
devs = []
while i < count do
devs << {
id: i,
serial: cached_serial(i),
path: cached_path(i)
}
i += 1
end
devs
end
I replaced the colons between the keys and values with "=>" 's to look like this:
def self.list
count = enumerate_vid_pid(vendor_id, product_id)
i = 0
devs = []
while i < count do
devs << {
id=>i,
serial=>cached_serial(i),
path=>cached_path(i)
}
i += 1
end
devs
end
Now the library loads and runs just fine.
Is the "key: value" a deprecated syntax? Too new for for my ruby?
def self.list count = enumerate_vid_pid(vendor_id, product_id) i = 0 devs = [] while i < count do devs << { id: i, serial: cached_serial(i), path: cached_path(i) } i += 1 end devs end
def self.list count = enumerate_vid_pid(vendor_id, product_id) i = 0 devs = [] while i < count do devs << { id=>i, serial=>cached_serial(i), path=>cached_path(i) } i += 1 end devs end
ruby --version ruby 1.8.7 (2012-02-08 patchlevel 358) [universal-darwin11.0]