irb

How to run IRB.start in context of current class

笑着哭i 提交于 2019-12-12 07:11:47
问题 I've been just going through PragProg Continuous Testing With Ruby , where they talk about invoking IRB in context of current class to inspect the code manually. However, they quote that if you invoke IRB.start in a class, self is predefined, and refers to the object we were in when start was called which isn't true in my case. Even for very simple example like a = "hello" require 'irb' ARGV.clear # otherwise all script parameters get passed to IRB IRB.start When I try to access the a

Ruby console alternative for IRB (Windows)

余生长醉 提交于 2019-12-12 06:55:05
问题 I am looking for some free light-weight GUI alternative for IRB console on windows. What I whould like to see: Area to write a script (so I can edit, run, edit...) Command line to play with current variables Output window to see results Intellisence Breakpoints/debugging is a plus Actually, some thing similar to powershell_ise.exe whould be great. P.S. I am not looking for IDE (NetBeans, Aptana, etc.) 回答1: How does SciTE fail? Kinda curious because it feels like what you are looking for if

Command not found when I call `./myshell` in ruby

不问归期 提交于 2019-12-11 10:28:25
问题 Today, I tried to call a script from ruby. I did like this: `./aaa.sh`, but it returned 'command not found', here is the session log of irb: irb(main):012:0> `which aaa.sh` => "/root/rocky/aaa.sh\n" irb(main):013:0> `aaa.sh` (irb):13: command not found: aaa.sh => "" irb(main):014:0> `./aaa.sh` (irb):14: command not found: ./aaa.sh => "" But, if I call it as 'sh aaa.sh', it works. irb(main):015:0> `sh aaa.sh` => "aaa.sh\ntest.rb\n" so, what's wrong whith this? 回答1: A couple possibilities

Why does irb -r make __FILE__ an absolute path?

寵の児 提交于 2019-12-11 10:03:07
问题 foo.rb is a one-liner that puts __FILE__ irb -r ./foo.rb gives me the absolute path to foo.rb. This is not the behavior if I run ruby foo.rb . Why is it happening in irb? irb 0.9.6(09/06/30), ruby 1.9.3p327 回答1: The reason this happens in IRB is the same reason this would happen if you had written a program named bar.rb with the following contents. require './foo' You will find that using IRB with the require as you do is no different than calling bar.rb which has the require. From the

frequently flush irb history to file

为君一笑 提交于 2019-12-10 22:35:20
问题 irb can write command history to a file, but it only does this when your irb session ends. I would like to write out my command history more frequently: as often as on every command (like shell history), but it doesn't have to be so often. Is there a .irbrc setting for this? Or will I have to hack the irb source... 回答1: Having hacked on irb many a time, good luck with a clean solution. Instead I'd recommend ripl, an irb alternative. By default it saves history more intelligently (i.e. even

Why does irb echo the right hand side of an assignment instead of the return value in the case of a setter method?

≯℡__Kan透↙ 提交于 2019-12-10 21:02:23
问题 It seems surprising that in all other instances irb will echo the return value of a method. Why does assignment via a setter behave differently? I'm using Ruby 2.2.2. irb(main):001:0> def x=(value); puts "puts_from_x"; "returned_string_from_x"; end => nil irb(main):002:0> self.x = 3 puts_from_x => 3 update It has dawned on me that it echoes the rhs because that's the actual return value . Why is this? 回答1: Following the @Matz reply in this thread : Setters always return the value they were

Change Font dynamically in console

醉酒当歌 提交于 2019-12-10 20:36:34
问题 Is there a proper plugin or a class to change font size, font type and decoration within a common output console? You can change terminal's font by going into preferences but that is not what I'm looking for here. I want to be able to change font dynamically from within code. Is there anything in Ruby or some terminal commands to do so (I use Mac OS X). 回答1: The font/font size used in ANSI terminals are implementation specific, and ANSI color/style codes are the only way to provide decoration

ruby irb on windows using gitbash shell - can't use arrow keys to modify command input?

房东的猫 提交于 2019-12-10 19:23:23
问题 when I do rails console my git bash shell permits me to use up arrow to recall commands, and use left/right arrows to modify the text I'm entering when I run irb the shell ignores backspace and arrow keys I'm not sure why the arrow keys would work fine in the shell for rails console but not when running irb ? 回答1: As I just wrote in the related Backspace and arrow keys aren't working in IRB(Git Bash console) on windows machine: running irb with --noreadline solved this problem for me: irb -

How to avoid 'no such file to load — map_by_method' script/console with bundler?

狂风中的少年 提交于 2019-12-10 16:16:24
问题 I am running rails 2.3.10 with bundler . I use rvm , in global gemsets usually I put the gems useful for the irb. By default I had these there: map_by_method, what_methods, ap, net-http-spy, hirb, looksee, pp, wirble. When I start irb, the gems it needs are avalaible for it, and the things look as they should. However, when I start script/console, it cannot reach the gems in the current rvm gemset only those which are defined in Gemfile . I get message no such file to load -- map_by_method .

What is the class of “if/unless” etc

最后都变了- 提交于 2019-12-10 13:47:59
问题 Considering that everything in Ruby is an object and we can open irb and type things like 4.class and "Text".class to see from which class an object is, why do if.class and unless.class give no return value? 回答1: Considering that everything in Ruby is an object That depends on your definition of " object " and every-" thing ". " Object " can mean " entity that can be manipulated by the program " (which I will call object from now on), or " value that is a member of the object system " (which