irb

A JSON text must at least contain two octets

谁说我不能喝 提交于 2019-11-29 20:49:54
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 you don't know what an octet is, read this post for a summary and solution: What is a JSON octet and why

Rails 3 - How can you get access to Devise's current_user in the IRB console?

守給你的承諾、 提交于 2019-11-29 20:41:56
I'm doing some design/debugging in IRB and need to login a user and then be able to use current_user in my efforts. From Brian Deterling's answer to another question, I have been able to successfully login and access a page response with this sequence: >> ApplicationController.allow_forgery_protection = false >> app.post('/sign_in', {"user"=>{"login"=>"some-login-id", "password"=>"some-password"}}) >> app.get '/some_other_path_that_only_works_if_logged_in' >> pp app.response.body NOTE: If you get a 200 response you are not logged in. You need a 302 redirect to indicate a successful login. See

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

我的未来我决定 提交于 2019-11-29 19:52:21
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_exit", "instance_variable_defined?", "irb_cb", "equal?", "freeze", "irb_context ", "irb_pop_workspace",

Why word 'translate' is messing irb?

末鹿安然 提交于 2019-11-29 16:01:46
I don't understand why my method translate undefines start_with? method and is messing something in irb, so I can exit irb only by pressing Ctrl + d , not exit or quit : >> "hello".respond_to?(:start_with?) => true >> def translate(string) >> if string.start_with?("a", "e", "i", "o", "u") >> string += "ay" >> end >> end NoMethodError: undefined method `start_with?' for #<RubyVM::InstructionSequence:0x00000001d4c960> from (irb):3:in `translate' from /usr/local/rvm/rubies/ruby-2.3.0/bin/irb:11:in `<main>' >> "hello".respond_to?(:start_with?) NoMethodError: undefined method `start_with?' for

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

喜欢而已 提交于 2019-11-29 14:53:46
问题 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

Ruby puts not outputting in real time

两盒软妹~` 提交于 2019-11-29 11:31:05
I've started some problems on Project Euler . One of the questions: The prime factors of 13195 are 5, 7, 13 and 29. What is the largest prime factor of the number 600851475143 ? I have some code written up...and it works: class Integer def primeFactors load('/home/arseno/ruby/lib/prime.rb') a = [] for i in (1..self) div = self.to_f/i.to_f if((div==div.to_i)&&(Prime.prime?(i))) a << i end end a end end puts 13195.primeFactors Outputs: 5 7 13 29 So far so good! Now, when I put in 600851475143 instead, my terminal hangs up (rightfully so, it's computing a whole lot of stuff!) So what I attempted

Is there a way to get out of a “hung” state in IRB?

丶灬走出姿态 提交于 2019-11-29 10:54:55
When using irb or rails console , I sometimes get stuck. For example, I forget a closing quote, so when I press enter, it's still waiting on that. Sometimes I can get out of this (by suppyling the closing quote, for example), but sometimes I can't. If not, I usually do the following: # Suspend the irb or console process (Control + Z) # Kill the last suspended process kill -9 % This is annoying and disrupts whatever I was doing in the console. What I'd like is an equivalent to Control + C on the command line, to say "forget that - give me a new prompt", so I can continue working in the console.

Reload the rails console

狂风中的少年 提交于 2019-11-29 10:49:02
问题 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}

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

十年热恋 提交于 2019-11-29 10:40:16
问题 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. 回答1: Same thing happened to me. Running irb with --noreadline solved my problem: irb --noreadline 回答2: Seems you didn't have readline installed while compile ruby. So install readline, maybe also readline-devel

How to use RSpec expectations in irb

落花浮王杯 提交于 2019-11-29 02:52:36
问题 I'd want to use [1,2,3].should include(1) in irb. I tried: ~$ irb 1.9.3p362 :001 > require 'rspec/expectations' => true 1.9.3p362 :002 > include RSpec::Matchers => Object 1.9.3p362 :003 > [1,2,3].should include(1) TypeError: wrong argument type Fixnum (expected Module) from (irb):3:in `include' from (irb):3 from /home/andrey/.rvm/rubies/ruby-1.9.3-p362/bin/irb:16:in `<main>' But it doesn't work though it's a valid case. How can I use [1,2,3].should include(1) ? 回答1: You are close, but calling