require 'rubygems' require 'irb' # ensure we use local gem $LOAD_PATH.unshift('lib') def consolize &block yield IRB.setup(nil) irb = IRB::Irb.new IRB.conf[:MAIN_CONTEXT] = irb.context irb.context.evaluate("require 'irb/completion'", 0) trap("SIGINT") do irb.signal_handle end catch(:IRB_EXIT) do irb.eval_input end end consolize do require 'echonest' key = nil locations = ["~/.mreko/echonest_api.key", "~/.echonest/api_key"] locations.each do |config| if File.exists?(File.expand_path(config)) key = File.read(File.expand_path(config)) break end end raise "Need an EN key in one of these locations: #{locations.inspect}" unless key @en = Echonest(key) def en; @en; end end