json - How do you use ruby gems after they have been installed on OS X -


i able install json library using ruby gems. in case it's relevant, i'm using latest os x.

usr$ sudo gem install json password: building native extensions.  take while... installed json-1.6.5 1 gem installed installing ri documentation json-1.6.5... installing rdoc documentation json-1.6.5... 

however, attempting require 'json' doesn't work. doing wrong?

touakas-macbook-pro:tmp jacob$ ruby x.rb x.rb:3:in `require': no such file load -- json (loaderror)     x.rb:2 

the x.rb follows:

#!/usr/bin/env ruby require 'json'  x = { "a"=>"b" } print x.to_json 

you need load rubygems first:

require 'rubygems' require 'json' 

edit:

according comment below, you'd better use ruby -rubygems x.rb rather require rubygems directly (suppose you're writing module resue).

credit to: @injekt , @ingenu


Comments

Popular posts from this blog

delphi - How to convert bitmaps to video? -

jasper reports - Fixed header in Excel using JasperReports -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -