irb

irb loading wrong ruby and gem path, using rbenv

别说谁变了你拦得住时间么 提交于 2019-12-09 23:31:54
问题 I started using rbenv for ruby version management and I'm finding that irb not loading the correct ruby version and gem version. Here are the details. irb Gem.path says: `>> Gem.path => ["/Users/Air/.gem/ruby/1.8", "/Library/Ruby/Gems/1.8", "/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8"]` Now in irb if I type: puts $: `>> puts $: /Library/Ruby/Site/1.8 /Library/Ruby/Site/1.8/powerpc-darwin11.0 /Library/Ruby/Site/1.8/universal-darwin11.0 /Library/Ruby/Site

Extend IRB main methods

血红的双手。 提交于 2019-12-08 10:17:29
问题 I have a directory structure in my app. For development purposes (and possibly beyond), I currently have a class X which has class methods pwd , cd , and ls . Is there a way to make these methods available when I enter irb whithin my app, for example: 2.1.5 :0 > pwd /current_dir/ Currently I am doing: 2.1.5 :0 > X.pwd /current_dir/ which is simply inconvenient. A solution where I could simply add something to my existing class would be perfect, like: class X < Irb::main def self.pwd #stuff

IRB escapes UTF characters

百般思念 提交于 2019-12-08 04:31:10
问题 I'm using OS-X (10.10.5) and rbenv (1.0.0) Ruby (2.2.4p230) and Fish Shell (2.2.0). When I type non ASCII characters in irb they are automatically escaped. max@MaxBook ~/p/sandbox> echo "Ö" Ö max@MaxBook ~/p/sandbox> irb irb(main):001:0> \U+FFC3\U+FFB6 I though at first this could be a problem with the shell or my Terminal settings but it only happens in IRB. Changing shells or ruby versions does not effect it. I did not have this problem on my previous laptop which had an almost identical

How to get irb and rails console to work properly in gitbash?

[亡魂溺海] 提交于 2019-12-07 08:10:34
问题 I'm using gitbash ver 2.9.0, 64-bit, on Windows 7. It uses mintty version 2.0.3. The gitbash shell most of the time seems to work fine. You can use the arrow keys, etc, as with any bash shell and they perform as expected, being able to scroll through prior commands, etc. However, when using irb or rails console (which runs irb ) it is very flakey. Rather than scroll through prior commands, the up arrow just moves the cursor up the screen and enters what are probably up arrow control codes

How do I get the “irb(main):001:0>” prompt instead of “>>”

混江龙づ霸主 提交于 2019-12-07 07:36:56
问题 Ruby is preinstalled on my Mac and so I wanted to have a look at it. First thing I noticed, is that irb prompts >> instead of irb(main):001:0>. I can't find anything on how to change this with Google because everyone is using irb(main):001:0> in their code ;-) Can you help me out? PS: It's not that I think Ruby is broken, but I want to look more nerdy while programming ;-) 回答1: $ irb --help Usage: irb.rb [options] [programfile] [arguments] --prompt prompt-mode --prompt-mode prompt-mode Switch

IRB escapes UTF characters

梦想与她 提交于 2019-12-07 04:28:27
I'm using OS-X (10.10.5) and rbenv (1.0.0) Ruby (2.2.4p230) and Fish Shell (2.2.0). When I type non ASCII characters in irb they are automatically escaped. max@MaxBook ~/p/sandbox> echo "Ö" Ö max@MaxBook ~/p/sandbox> irb irb(main):001:0> \U+FFC3\U+FFB6 I though at first this could be a problem with the shell or my Terminal settings but it only happens in IRB. Changing shells or ruby versions does not effect it. I did not have this problem on my previous laptop which had an almost identical configuration. What is going on here? spickermann You can enable unicode support in IRB by recompiling

File.open and blocks in Ruby 1.8.7

岁酱吖の 提交于 2019-12-07 03:25:12
问题 I'm pretty new to ruby and I'm currently reading the Pickaxe book to get familiar with everything. I came across the File.open section where it discusses taking a block as a parameter to a File.open call then guaranteeing that the file is closed. Now this sounds like an absolutely brilliant way to avoid shooting yourself in the foot and as I'm dangerously low on toes, I figure I'll give it a go. Here is what I wrote (in irb if that matters): File.open('somefile.txt', 'r').each { |line| puts

RangeError: bignum too big to convert into `long'

大城市里の小女人 提交于 2019-12-06 14:38:34
num = "0000001000000000011000000000000010010011000011110000000000000000" for n in 0...num.length temp = num[n] dec = dec + temp*(2**(num.length - n - 1)) end puts dec When i am running this code in irb the following error message is the output. and when i compiled the same logic in python it is working absolutely fine. I have Googled "RangeError: bignum too big to convert into `long': but didn't find the relevant answer. Please help me :( Thanks in Advance. RangeError: bignum too big to convert into long' from (irb):4:in *' from (irb):4:in block in irb_binding' from (irb):2:in each' from (irb)

Truncate #inspect output in irb (ruby)

久未见 提交于 2019-12-06 08:56:59
问题 I want to truncate #inspect output in irb (a large output must be cropped to MAX_LEN). Currently, I override :inspect, :to_s methods for all specific objects. Is there are other solution? change $stdout ? other? 回答1: For a clean solution, gem install hirb . hirb pages irb's returned values if they get too long. If you want to monkeypatch irb: module IRB class Irb def output_value @context.last_value.to_s.slice(0, MAX_LEN) end end end I don't recommend this because it's a hack and breaks any

Does Ruby use $stdout for writing the output of puts and return?

别来无恙 提交于 2019-12-06 03:08:33
问题 I want to know the output stream being used by Ruby to print these things at the command-line: irb(main):001:0> a="test" => "test" irb(main):002:0> puts a test => nil irb(main):003:0> a => "test" Is $stdout used for irb(main):002:0> and irb(main):003:0> ? And, is there any change in the value of $stdout between those two invocations? Also, can some one point me to the Ruby source from where these things get printed/written? 回答1: Yes. And it's easy to test/prove to yourself. Try this at the