irb

How to get nice formatting in the Rails console

帅比萌擦擦* 提交于 2019-12-29 02:21:11
问题 I want to get something like this to look nice: >> ProductColor.all => [#<ProductColor id: 1, name: "White", internal_name: "White", created_at: "2009-06-10 04:02:44", updated_at: "2009-06-10 04:02:44">, #<ProductColor id: 2, name: "Ivory", internal_name: "Ivory", created_at: "2009-06-10 04:02:44", updated_at: "2009-06-10 04:02:44">, #<ProductColor id: 3, name: "Blue", internal_name: "Light Blue", created_at: "2009-06-10 04:02:44", updated_at: "2009-06-10 04:02:44">, #<ProductColor id: 4,

Defining and calling a method in irb

馋奶兔 提交于 2019-12-24 13:41:05
问题 I'm struggling with understanding understanding OOP. I am trying to use IRB to play around with Ruby and deepen my understanding. In IRB foo = Object.new Creates a new object However if I try and give irb a definition and call it on that object it doesn't work. (does the def have to happen in a .rb file and loaded into Ruby?) def bar "hello" end 回答1: You need to define the method in the class you want it to apply to. class NewObject def foo puts "hello" end end these methods are called like:

Why do I get “stack level too deep” from method_missing in irb 1.9.3?

吃可爱长大的小学妹 提交于 2019-12-23 18:05:50
问题 Scenario: -bash-3.2$ irb -f ruby-1.9.3-p0 :001 > @v = {} => {} ruby-1.9.3-p0 :002 > def method_missing(sym, *args); @v[sym]; end => nil ruby-1.9.3-p0 :003 > a (irb):2: stack level too deep (SystemStackError) -bash-3.2$ I ran with -f to avoid loading any irbrc stuff. I'm expecting to get nil when I input a . What's going on, and is there a workaround? I tried wrapping a with a begin / rescue Exception block but that didn't do anything. This also happens with 1.9.2, but not 1.9.1. More strange

Rails console tips, tricks and customizations

爷,独闯天下 提交于 2019-12-23 08:08:18
问题 There's this great post on irb tricks, but what about further customizing Rails console behavior and output? Awesome print and Hirb are great. SQL logging is a must for me. In your ~/.irbrc paste: require 'logger' ActiveRecord::Base.logger = Logger.new(STDOUT) if defined?(Rails) What's your tip/trick/gem of choice? 回答1: I've recently written a rails specific console tweaks blog post: https://rbjl.janlelis.com/49-railsrc-rails-console-snippets (as gist) 回答2: Open last migration in your editor

Rails console tips, tricks and customizations

穿精又带淫゛_ 提交于 2019-12-23 08:08:10
问题 There's this great post on irb tricks, but what about further customizing Rails console behavior and output? Awesome print and Hirb are great. SQL logging is a must for me. In your ~/.irbrc paste: require 'logger' ActiveRecord::Base.logger = Logger.new(STDOUT) if defined?(Rails) What's your tip/trick/gem of choice? 回答1: I've recently written a rails specific console tweaks blog post: https://rbjl.janlelis.com/49-railsrc-rails-console-snippets (as gist) 回答2: Open last migration in your editor

RangeError: bignum too big to convert into `long'

人走茶凉 提交于 2019-12-23 00:46:12
问题 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

word boundaries in irb

筅森魡賤 提交于 2019-12-22 08:00:04
问题 I'm using Terminal on Snow Leopard. At the command line, if I've typed foo.bar.baz.bang.quuz.quux , when i tap option-B, it moves the cursor backward word by word -- stopping at every period, because it considers a period to be a word boundary. Likewise, option-F moves forward word by word. In irb (0.9.5, ruby 1.8.7), option-B and -F also have this behavior, but the period is no longer treated as a word boundary, which makes these keyboard shortcuts significantly less useful. How can I change

How do I compile Readline support into Ruby

独自空忆成欢 提交于 2019-12-22 04:25:22
问题 My version of ruby was compiled with editline (on os x) and I miss the features of readline in irb . How do I recompile ruby with readline support? 回答1: Install readline to /usr/local Recompile ruby from scratch and use the --with-readline-dir=/usr/local switch or if you have downloaded the ruby sources earlier and built it by hand, Go to the ext/readline folder of your ruby source tree Type ruby extconf.rb and then run the make && make install procedure for ruby. 回答2: There's also a pure

rails console fails with `Switch to inspect mode` in windows

不问归期 提交于 2019-12-22 03:30:34
问题 I create a rails project by rails new foo , then cd foo , and run rails c . Then I got message like this. DL is deprecated, please use Fiddle Loading development environment (Rails 4.0.2) Switch to inspect mode. That's all. I can't use rails console. Have you any idea what am I doing wrong? I'm using railsinstaller with ruby 1.9.3 and 2.0.0 both, and ruby 2.0.0p451 (2014-02-24) [i386-mingw32] from Rubyinstaller. All versions fails with same error. There is no problem with simple irb command.

Pasting text into IRB is incredibly slow. Readline issue?

ぃ、小莉子 提交于 2019-12-22 02:01:01
问题 When I paste the following text into IRB or PRY running under ruby-enterprise-2011.03, it takes 13 seconds. # Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Pasting isn't slow when running irb with other ruby installations on the same computer. jruby-1.5.6 jruby-1.6.3 ruby-1.8.6-p420 ruby-1.8.7-p352 ruby-1.9.1-p431 ruby-1.9.2-p290 ruby-1.9.3-preview1 or Mac OS X's default system install of 1.8.7-p249 This question