irb

How to format irb command prompt

帅比萌擦擦* 提交于 2019-11-28 09:12:57
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? The irb man page has a section on " Customizing prompt ". Here's mine for example: IRB.conf[:PROMPT][:CUSTOM] = { :PROMPT_I => ">> ", :PROMPT_S => "%l>> ", :PROMPT_C => ".. ", :PROMPT_N => ".. ",

Ruby puts not outputting in real time

孤人 提交于 2019-11-28 05:20:04
问题 I've started some problems on Project Euler. One of the questions: The prime factors of 13195 are 5, 7, 13 and 29. What is the largest prime factor of the number 600851475143 ? I have some code written up...and it works: class Integer def primeFactors load('/home/arseno/ruby/lib/prime.rb') a = [] for i in (1..self) div = self.to_f/i.to_f if((div==div.to_i)&&(Prime.prime?(i))) a << i end end a end end puts 13195.primeFactors Outputs: 5 7 13 29 So far so good! Now, when I put in 600851475143

Is there a way to get out of a “hung” state in IRB?

谁都会走 提交于 2019-11-28 03:53:58
问题 When using irb or rails console , I sometimes get stuck. For example, I forget a closing quote, so when I press enter, it's still waiting on that. Sometimes I can get out of this (by suppyling the closing quote, for example), but sometimes I can't. If not, I usually do the following: # Suspend the irb or console process (Control + Z) # Kill the last suspended process kill -9 % This is annoying and disrupts whatever I was doing in the console. What I'd like is an equivalent to Control + C on

IRB history not working with Ruby 2.3.0

。_饼干妹妹 提交于 2019-11-27 22:45:43
I have Ruby 2.3.0p0 installed via rbenv, on OS X 10.11.4. Within an IRB session, history works fine. However, I cannot access IRB history across sessions. I tried my system Ruby, 2.0.0p648, and history across IRB sessions works fine. I tried installing that same version of Ruby via rbenv, and it also has working history. I've compared the values of IRB.conf between a working and nonworking session, and nothing looks out of place (although, weirdly, irb/ext/save-history.rb is a blank file in both cases). Looking at my .irb_history file, it appears that it is getting replaced, rather than

rbenv irb history is not saving

点点圈 提交于 2019-11-27 15:59:33
问题 I install ruby via rbenv-installer. When I use irb console, I can use history by pressing up and down on keyboard. And when I exited from console and start it again, I can't use prewious history. When I press up-arrow-button, nothing was happened. When I used rvm this option was working. How can I switch on it in rbenv? 回答1: I found this way for solving my problem. In file ~/.irbrc write: require 'irb/ext/save-history' #History configuration IRB.conf[:SAVE_HISTORY] = 100 IRB.conf[:HISTORY

How do I make vi editing-mode work in IRB when using RVM?

丶灬走出姿态 提交于 2019-11-27 14:56:13
问题 I " set editing-mode vi " in my .inputrc on my Mac OS system, which allows vi editing in IRB. When I'm using a RVM Ruby, the IRB sessions don't process this directive. Does anyone know a solution? 回答1: Have you got set -o vi set, either at the command-line or in one of your startup scripts? That turns it on for the shell. I have both " set editing-mode vi " and set -o vi and have Vi-like editing in IRB. EDIT: Try creating ~/.editrc , put bind -v in it. Snow Leopard has support for editline

irb history not working

﹥>﹥吖頭↗ 提交于 2019-11-27 13:52:33
问题 in ~/.irbrc i have these lines: require 'irb/ext/save-history' #History configuration IRB.conf[:SAVE_HISTORY] = 100 IRB.conf[:HISTORY_FILE] = "#{ENV['HOME']}/.irb-save-history" and yet when i run irb and hit the up arrow nothing happens. also the irb history file specified is not getting created and nothing is logged to it. 回答1: I don't have an answer for you why the above doesn't work, but I did find a file, /etc/irbrc on my system (OS X - Snow Leopard, Ruby 1.8.7) that does provide a

Reload rubygem in IRB

半世苍凉 提交于 2019-11-27 12:29:55
问题 Is there a way to "reload" or "refresh" a rubygem in memory? As i'm playing in irb, occasionally I like to modify my gem files, and if i require the same gem, it does not update into memory and gives the output "false". Currently I have to exit IRB, get back into IRB and then require the gem again, there has to be a better way...what is it? 回答1: As others have suggested, you can use Kernel#load. However, don't waste your time finding and loading each gem file as all files that have been

Ruby: How to make IRB print structure for Arrays and Hashes

ⅰ亾dé卋堺 提交于 2019-11-27 10:05:58
问题 When I make a new array/hash in irb , it prints out a nice format to show the structure, ex. ["value1", "value2", "value3"] {"key1" => "value1"} ... but when I try to print out my variables using puts , I get them collapsed: value1 value2 value3 key1 value1 I gather that puts is not the right command for what I want, but what is? I want to be able to view my variables in irb in the first format, not the second. 回答1: You can either use the inspect method: a=["value1", "value2", "value3"] puts

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

天大地大妈咪最大 提交于 2019-11-27 09:03:39
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. While it is true that you cannot access local variables defined in required files, you can access constants, and you can access anything stored in an object that you have access to