irb

How can I reload a script in IRB?

核能气质少年 提交于 2019-11-29 02:01:47
问题 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__)}/..

rbenv irb history is not saving

安稳与你 提交于 2019-11-29 01:31:38
I install ruby via rbenv-installer . When I use irb console, I can use history by pressing up and down on keyboard. And when I exited from console and start it again, I can't use prewious history. When I press up-arrow-button, nothing was happened. When I used rvm this option was working. How can I switch on it in rbenv? arturtr I found this way for solving my problem. In file ~/.irbrc write: require 'irb/ext/save-history' #History configuration IRB.conf[:SAVE_HISTORY] = 100 IRB.conf[:HISTORY_FILE] = "#{ENV['HOME']}/.irb-save-history" Found in this question: irb history not working Create ~/

How to suppress the output of return value in IRB/Rails Console?

百般思念 提交于 2019-11-28 19:43:38
问题 An example is if I go into IRB and do the following: jruby-1.6.7 :026 > puts [1,2,3,4,5] 1 2 3 4 5 => nil Is there anyway to suppress the nil ? The problem is if I put in a large data structure, it spams something an other irrelevant return respond. I'm more interested in seeing output from debug statements I run through a block and have to continually scroll up and look for the real data. 回答1: If you just want to suppress long output once in a while, use ;0 , like: a = [*1..10000];0 # => 0

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

那年仲夏 提交于 2019-11-28 17:03:21
问题 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. 回答1: 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. 回答2: Pry (an IRB alternative) also lets you do this, in fact it was

A JSON text must at least contain two octets

假如想象 提交于 2019-11-28 16:57:16
问题 I received this error, and I couldn't find any reasonable answer to this question, so I thought I'd write a summary of the problem. If you run this snippet in irb: JSON.parse( nil ) You'll see the following error: TypeError: can't convert nil into String I was kind of expecting the function to return nil , and not a TypeError . If you convert all input using to_s , then you'll see the octet error: JSON::ParserError: A JSON text must at least contain two octets! That's just fine and well. If

Ruby: How to make IRB print structure for Arrays and Hashes

大兔子大兔子 提交于 2019-11-28 16:56:45
When I make a new array/hash in irb , it prints out a nice format to show the structure, ex. ["value1", "value2", "value3"] {"key1" => "value1"} ... but when I try to print out my variables using puts , I get them collapsed: value1 value2 value3 key1 value1 I gather that puts is not the right command for what I want, but what is? I want to be able to view my variables in irb in the first format, not the second. You can either use the inspect method: a=["value1", "value2", "value3"] puts a.inspect Or, even better, use the pp (pretty print) lib: require 'pp' a=["value1", "value2", "value3"] pp a

How to suppress Rails console/irb outputs

不羁的心 提交于 2019-11-28 15:51:20
I'm stuck with a pretty weird problem. I was testing some db entries in our production server in Rails Console where almost all the commands were resulting a huge number of o/p lines, due to which the ssh channel was getting hanged :( Is there a way to suppress the console/irb screenfuls? Thanks You can append ; nil to all your your commands/statements. Example: users = User.all; nil Actually irb prints the (return) value of the last executed statement. Thus in this case it'll print only nil as nil is the last executed valid statement :) LarsDK In search of a solution how to silence the irb

How do you list the currently available objects in the current scope in ruby?

最后都变了- 提交于 2019-11-28 15:38:53
问题 I'm new to ruby and I'm playing around with the IRB. I found that I can list methods of an object using the ".methods" method, and that self.methods sort of give me what I want (similar to Python's dir( builtins )?), but how can I find the methods of a library/module I've loaded via include and require? irb(main):036:0* self.methods => ["irb_pop_binding", "inspect", "taguri", "irb_chws", "clone", "irb_pushws", "public_methods", "taguri=", "irb_pwws", "public", "display", "irb_require", "irb

How to run a .rb file from IRB?

妖精的绣舞 提交于 2019-11-28 15:20:30
I am starting out with Ruby on Rails. I am currently going through a tutorial where it says that I have to run a .rb file from IRB and that that will create a .xml file in my current directory. My question is how do I run a .rb file in IRB? And do I have to be in the directory where this .rb file lives when I run it in IRB? I tried the following: just typing irb on the command line in the directory of the file. That starts an IRB session as far as I understand. Then I typed irb "filename.rb" which went through but didn't create anything in the current directory but at least it didn't give any

How to get nice formatting in the Rails console

时间秒杀一切 提交于 2019-11-28 15:11:10
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, name: "Green", internal_name: "Green", created_at: "2009-06-10 04:02:44", updated_at: "2009-06-10 04:02:44