Questions tagged [irb]

Interactive Ruby (IRB) is a shell for programming in Ruby. The program can be launched from a command prompt and allows the execution of Ruby commands line by line.

Interactive Ruby Shell (IRB) is a shell for programming in Ruby. The program can be launched from a command prompt and allows the execution of Ruby commands line by line. It features command history, line editing capabilities, and job control, and is able to communicate directly as a shell script over the Internet and interact with a live server. It was developed by Keiju Ishitsuka.

772 questions
4
votes
4 answers

rvm, irb and require - not working for installed gems under irb

I have just installed rvm today and it looks really handy/powerful. I think I am getting the hang of it, but... When using an rvm installed ruby, and running irb, when I require an installed gem, something, like 'rvm', I get: > kimptoc$ rvm use…
Chris Kimpton
  • 5,546
  • 6
  • 45
  • 72
4
votes
3 answers

Debug into method from production irb

When I look for a problem, for example with a specific ActiveRecord object, I often find myself doing the following on my production system: # RAILS_ENV=production bundle exec irb(main)> article = Article.find(123) => #
4
votes
1 answer

What is it _|_ in Ruby language?

I've seen this thing it smarterer.com tests. I've tested it in irb like this: 2.2.0 :019 > puts _|_ 13 => nil 2.2.0 :020 > c = a.to_s.to_i;c+=1;i=13;puts _|_ false => nil So strange behavior. So what this thing is and what should it do ?
dsounded
  • 703
  • 5
  • 21
4
votes
3 answers

Where does the variable "p" get it's value from in ruby if it's not defined explicitly?

Question: Where does p get it's value from below and why does it happen? Consider this irb session: me@somewhere:~$ irb irb(main):001:0> a NameError: undefined local variable or method `a' for main:Object from (irb):1 irb(main):002:0>…
Dafydd Rees
  • 6,941
  • 3
  • 39
  • 48
4
votes
2 answers

What's the difference between the ruby irb prompt modes?

I can change the irb prompt mode with irb --prompt prompt-mode I can see what null and simple does, but I can't tell the difference between null and xmp and the difference between default/classic/inf-ruby. Can someone explain to me what these other…
Steven
  • 2,538
  • 3
  • 31
  • 40
4
votes
1 answer

tiny_tds: Segmentation fault

This is similar to this question. However, the answer posted on that question, didn't work for me. I have installed freetds on my Mac. I have specified the following in my GemFile. gem 'tiny_tds' gem 'activerecord-sqlserver-adapter', '~> 4.1.0' And…
Indrajeet
  • 521
  • 3
  • 9
  • 23
4
votes
4 answers

Ruby: How to include namespaced classes into global namespace in IRB

For some reason I want to use namespaced Classes/Modules as they are in global namespace in IRB. For example I have module MyCore and class MyUser inside it. Is there any mechanism or hook for IRB to include MyCore::MyUser in a way I can call just…
Roman Trofimov
  • 109
  • 1
  • 6
4
votes
2 answers

Escape line breaks in puts output

In IRB on Ruby 1.8.7, I have a collection of strings I'm working with that have newlines in them. When these newlines are output, I want to explicitly see the \r and \n characters within my strings. Is there some way to tell puts to escape those…
Kevin
  • 14,655
  • 24
  • 74
  • 124
4
votes
1 answer

Call a method and initiate debugging from the rails console without editing the source code?

Sometimes when I'm working in the rails console, I find I want to step through a particular method (from my rails app) in the debugger. In the past I have done this by temporarily adding a debugger statement to the source code of the method, then…
antinome
  • 3,408
  • 28
  • 26
4
votes
2 answers

Best way to stop load script execution in Ruby on Rails's IRB

Looking for the best way to exit a loaded script in Ruby on Rails's IRB. Kernel.exit & Kernel.abort will pop you out of the IRB session altogether. Ideally, this would happen on some conditional criteria. My script/my_script.rb: puts "My Script is…
spyle
  • 1,960
  • 26
  • 23
4
votes
1 answer

show app name in heroku console

If I run a console on heroku, it looks like this: heroku run console --app myapp-production irb(main):001:0> This seems a whole lot more dangerous than something like this: heroku run console --app myapp-production myapp-production:001:0> Anyone…
Peter Ehrlich
  • 6,969
  • 4
  • 49
  • 65
4
votes
1 answer

Basic Ruby Time Operations Not Working

I've been trying to test out some stuff in irb and it doesn't recognize commands like 2.weeks.ago and 10.hours.ago The error I get is the following: 1.9.3p258 :002 > 2.weeks.ago NoMethodError: undefined method `weeks' for 2:Fixnum from…
avk
  • 93
  • 1
  • 5
4
votes
2 answers

What am I actually doing when calling Enumerable#reduce?

Why can't I call Enumerable#reduce(sym) without parentheses like the following? >> [1, 2, 3].reduce :+ ?> While using parentheses results in this: >> [1, 2, 3].reduce(:+) => 6 Am I accidentally calling Enumerable#reduce {| memo, obj | block }…
cyang
  • 5,574
  • 2
  • 25
  • 34
4
votes
3 answers

How to create a custom method for the rails console?

When I'm using the Rails console in Ubuntu for a long session I define the clear method: def clear; system 'clear' end So when my console is getting dirty the only thing I have to do is type clear and the console gets cleared. I would like to use…
sanrodari
  • 1,602
  • 2
  • 13
  • 23
4
votes
2 answers

Difference between .irb_history and .irb-history

What the difference is between the .irb-history and .irb_history files in Ruby?
wonbyte
  • 971
  • 2
  • 11
  • 23