irb

Can you 'require' ruby file in irb session, automatically, on every command?

给你一囗甜甜゛ 提交于 2019-11-30 23:39:13
问题 I am currently editing a file, and I'm using irb to test the api: > require './file.rb' > o = Object.new > o.method I then want to be able to edit the file.rb, and be able to see changes immediately. Example: assume new_method did not exist when I first required file.rb: > o.new_method Which will return an error. Is there a sandbox/developer mode or a method whereby I can achieve the above without having to reload the file every time? Require will not work after the first require, regardless.

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

故事扮演 提交于 2019-11-30 17:31:16
问题 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 modes do? It seems pointless to have multiple modes doing the same thing. 回答1: The answer to those questions lie in IRB.conf[:PROMPT] which is a hash whose keys are the different prompts and whose values are the configurations for each prompt.

Ruby: How to load a file into interactive ruby console (IRB)?

不羁的心 提交于 2019-11-30 10:16:54
问题 I am using IRB (interactive ruby console) to learn how to program with Ruby. How do I load a file into the console if I write my programs in a text editor first? 回答1: If you only need to load one file into IRB you can invoke it with irb -r ./your_file.rb if it is in the same directory. This automatically requires the file and allows you to work with it immediately. 回答2: Using ruby 1.9.3 on Ubuntu 14.04, I am able to load files from the current directory into irb with the following command

IRb: how to start an interactive ruby session with pre-loaded classes

折月煮酒 提交于 2019-11-30 09:50:28
As I am going through my journey by adopting the Ruby language, I spend a lot of time inside IRb. It's just fantastic! But, as I am not very aware of it's capabilities, and still a “nubby” with Ruby, I would like to know the following: How can I “flush” the session, without restarting IRb (or is this not possible). How can I configure IRb to load a bunch of source files "hello.rb" and "hello_objects.rb", i.e. at startup? I am heavily working in these and it would be nice to know a short hand to load these classes, without manually typing 'load' for each again. I'm not sure it's possible to

Can't enter Umlauts in Ruby 1.9.3 IRB

烈酒焚心 提交于 2019-11-30 08:46:19
I am experiencing very strange behavior in Ruby 1.9.3's IRB with Mac OS 10.7.3 When I try to enter an Umlaut, it's escaped in the prompt and looks like this (I entered "ü" on the keyboard) irb(main):001:0> "\U+FFC3\U+FFBC" What's super strange is this: irb(main):001:0> "\U+FFC3\U+FFBC".length => 0 Of course, the character isn't displayed either: irb(main):001:0> "\U+FFC3\U+FFBC" => "" Does anyone know what's going on here or how to fix this? Victor Moroz didn't quite give the definitive answer but his link led me to a solution (thx!): I forgot to mention: Im running homebrew I built ruby using

Reload the rails console

落爺英雄遲暮 提交于 2019-11-30 08:10:31
Regarding the use of Rails console, when I make some change on a model, do I need to reload the rails console every time to make that change reflects? For example, I have my original code as follows: class Article < ActiveRecord::Base validates :title, :presence => true validates :body, :presence => true end Later, I want to add some additional attribute as below. class Article < ActiveRecord::Base validates :title, :presence => true validates :body, :presence => true def long_title "#{title} - #{published_at}" end end Does it need to run the command "reload!" every time to be able to do the

Backspace and arrow keys aren't working in IRB(Git Bash console) on windows machine

泪湿孤枕 提交于 2019-11-30 08:07:22
I just installed ruby 1.9.2 on windows machine and Backspace or any other arrow keys don't work. This happens only when I open IRB on Git Bash console. But it works fine on Windows console. Any help on that? Note: IRB was working fine on both consoles with the earlier versions of ruby. Same thing happened to me. Running irb with --noreadline solved my problem: irb --noreadline Seems you didn't have readline installed while compile ruby. So install readline, maybe also readline-devel, then recompile ruby. You can also disable readline in ~/.irbrc IRB.conf[:USE_READLINE] = false As documented

How can I reload a script in IRB?

醉酒当歌 提交于 2019-11-30 04:36:51
I am writing a Ruby script for use in the Rails environment, but I chose to run it from irb because reloading the Rails console can be a pain. Now the wait time is much shorter from irb, but I'm bothered that I have to restart irb and require the script everytime I make a change. Is there a simpler way of reloading a script from irb? I found a method in this thread , but that only applies to gem files apparently. My require statement looks like this require "#{File.expand_path(__FILE__)}/../lib/query" EDIT: Having tried load rather than require , I still couldn't get it to work. I can't get a

How can I input multibyte characters in rails console (or irb)?

一世执手 提交于 2019-11-30 03:58:48
问题 guys. I am developing a Chinese application with rails. Now I want to input some Chinese characters in rails console but cannot do that, either in irb. Any guys who have the experience to solve this problem? I would appreciate your help! 回答1: Based on @Jimmy-Huang's answer, these are the steps I followed on Mac Leopard using rvm and ruby 1.9.2: rvm package install readline rvm remove 1.9.2 rvm install 1.9.2 --with-readline-dir=$rvm_path/usr That resulted in some errors, particularly when

How do I drop to the IRB prompt from a running script?

安稳与你 提交于 2019-11-29 21:22:52
Can I drop to an IRB prompt from a running Ruby script? I want to run a script, but then have it give me an IRB prompt at a point in the program with the current state of the program, but not just by running rdebug and having a breakpoint. you can use ruby-debug to get access to irb require 'rubygems' require 'ruby-debug' x = 23 puts "welcome" debugger puts "end" when program reaches debugger you will get access to irb. Pry (an IRB alternative) also lets you do this, in fact it was designed from the ground up for exactly this use case :) It's as easy as putting binding.pry at the point you