irb

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

与世无争的帅哥 提交于 2019-12-18 10:21:44
问题 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

Why word 'translate' is messing irb?

試著忘記壹切 提交于 2019-12-18 09:07:10
问题 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

How to run a .rb file from IRB?

房东的猫 提交于 2019-12-17 21:39:09
问题 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"

How to suppress Rails console/irb outputs

≡放荡痞女 提交于 2019-12-17 17:26:37
问题 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 回答1: 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

Regular expression “empty range in char class error”

别说谁变了你拦得住时间么 提交于 2019-12-17 16:45:14
问题 I got a regex in my code, which is to match pattern of url and threw error: /^(http|https):\/\/([\w-]+\.)+[\w-]+([\w- .\/?%&=]*)?$/ The error was "empty range in char class error". I found the cause of that is in ([\w- .\/?%&=]*)? part. Ruby seems to recognize - in \w- . as an operator for range instead of a literal - . After adding escape to the dash, the problem was solved. But the original regular expression ran well on my co-workers' machines. We use the same version of osx, rails and

IRB history not working with Ruby 2.3.0

六眼飞鱼酱① 提交于 2019-12-17 16:27:20
问题 I have Ruby 2.3.0p0 installed via rbenv, on OS X 10.11.4. Within an IRB session, history works fine. However, I cannot access IRB history across sessions. I tried my system Ruby, 2.0.0p648, and history across IRB sessions works fine. I tried installing that same version of Ruby via rbenv, and it also has working history. I've compared the values of IRB.conf between a working and nonworking session, and nothing looks out of place (although, weirdly, irb/ext/save-history.rb is a blank file in

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

放肆的年华 提交于 2019-12-13 13:25:00
问题 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 MyUser.new without prefixing it with MyCore ? 回答1: You can simply do include MyCore myUser = MyUser.new Using include adds all the constants in the module to you current class. class WhereIWantToIncludeMyCore include MyCore def initialize user =

How can I pass STDin to IRB without it exiting after processing this input?

依然范特西╮ 提交于 2019-12-13 06:06:36
问题 I'm using a short bash script to help me test an implementation of linked lists in ruby for class. I know about rspec and unit testing, and I'm certain they're better options for what I'm trying to do, but I was able to figure out this command echo "require './nodes'" | irb The output afterwards is Switch to inspect mode. require './nodes' true Technically a success, but the irb process ends there. So I tried echo "require './nodes'" | irb --noinspect Which gave me Switch to non inspect mode.

Include namespace in Rails 3.1 console

不打扰是莪最后的温柔 提交于 2019-12-13 01:07:04
问题 My Rails 3.1 application is completely implemented inside a namespace. When I open the Rails console I would like to be able to directly access identifiers inside my namespace. I would like not to have to type the full qualified names everytime. Instead of Aef::Newman::HandledAddress I would like to write HandledAddress Including the namespace inside the console like the following does not help for some reason: include Aef::Newman 回答1: You can create an irb sub-session, "moving into" the

How can I avoid the console output when assigning a value to a variable in Ruby

让人想犯罪 __ 提交于 2019-12-12 10:55:45
问题 Is it possible to escape that effect when assigning to a value: irb(main):584:0>a = true =>true irb(main):584:0> I have a code that has lots of assignings and when I am trying to test it I can not see the result because of all these returned values: true false true false true true .. 回答1: You can start the irb or console attaching the --noecho option. $ irb --noecho 2.0.0p353 :001 > true 2.0.0p353 :002 > Otherwise, if the console was started by another process, simply set conf.echo = false $