irb

Why isn't current directory on my Ruby path? [duplicate]

百般思念 提交于 2019-11-27 06:58:12
This question already has an answer here: Why does Ruby 1.9.2 remove “.” from LOAD_PATH, and what's the alternative? 7 answers Is there any reason why my present working directory is not on my Ruby path? Consider: ~:499$ irb ruby-1.9.2-p136 :002 > puts $: /Users/mrberryman/.rvm/rubies/ruby-1.9.2-p136/lib/ruby/site_ruby/1.9.1 /Users/mrberryman/.rvm/rubies/ruby-1.9.2-p136/lib/ruby/site_ruby/1.9.1/x86_64-darwin10.6.0 /Users/mrberryman/.rvm/rubies/ruby-1.9.2-p136/lib/ruby/site_ruby /Users/mrberryman/.rvm/rubies/ruby-1.9.2-p136/lib/ruby/vendor_ruby/1.9.1 /Users/mrberryman/.rvm/rubies/ruby-1.9.2

How to format irb command prompt

血红的双手。 提交于 2019-11-27 02:43:04
问题 Previously I was using Ruby 1.8 and my irb command prompt used to look like this: Air ~: irb >> a = 1 => 1 >> b = 2 => 2 >> a + b => 3 I installed rvm (and Ruby 1.9.2) and now my irb command prompt looks like this: Air ~: irb ruby-1.9.2-p180 :001 > a = 1 => 1 ruby-1.9.2-p180 :002 > b = 2 => 2 ruby-1.9.2-p180 :003 > a + b => 3 Is there a way to remove the ruby-1.9.2-p180 :001 from the command line? 回答1: The irb man page has a section on "Customizing prompt". Here's mine for example: IRB.conf[

How do I dynamically create a local variable in Ruby?

不问归期 提交于 2019-11-26 23:09:26
问题 I am trying to dynamically create local variables in Ruby using eval and mutate the local-variables array. I am doing this in IRB. eval "t = 2" local_variables # => [:_] eval "t" # => NameError: undefined local variable or method `t' for main:Object local_variables << "t".to_sym # => [:_, :t] t # => NameError: undefined local variable or method `t' for main:Object 回答1: You have to use the correct binding. In IRB for example this would work: irb(main):001:0> eval "t=2", IRB.conf[:MAIN_CONTEXT]

How can I access a variable defined in a Ruby file I required in IRB?

女生的网名这么多〃 提交于 2019-11-26 14:28:48
问题 The file welcome.rb contains: welcome_message = "hi there" But in IRB, I can't access the variable I just created: require './welcome.rb' puts welcome_message # => undefined local variable or method `welcome_message' for main:Object What is the best way to bring in predefined variables and have initialization work done when you require something into your IRB session? Global variables don't seem like the right path. 回答1: While it is true that you cannot access local variables defined in

Why isn&#39;t current directory on my Ruby path? [duplicate]

删除回忆录丶 提交于 2019-11-26 12:58:30
问题 This question already has answers here : Why does Ruby 1.9.2 remove “.” from LOAD_PATH, and what's the alternative? (7 answers) Closed 4 years ago . Is there any reason why my present working directory is not on my Ruby path? Consider: ~:499$ irb ruby-1.9.2-p136 :002 > puts $: /Users/mrberryman/.rvm/rubies/ruby-1.9.2-p136/lib/ruby/site_ruby/1.9.1 /Users/mrberryman/.rvm/rubies/ruby-1.9.2-p136/lib/ruby/site_ruby/1.9.1/x86_64-darwin10.6.0 /Users/mrberryman/.rvm/rubies/ruby-1.9.2-p136/lib/ruby