irb

How to require ActiveRecord In IRB

六月ゝ 毕业季﹏ 提交于 2019-12-04 04:59:35
问题 I would like to load the ActiveRecord gem in my IRB session, but the following is not working: require 'activerecord' 2.4.1 :004 > require 'activerecord' LoadError: cannot load such file -- activerecord from /Users/robskrob/.rvm/rubies/ruby-2.4.1/lib/ruby/site_ruby/2.4.0/rubygems/core_ext/kernel_require.rb:55:in `require' from /Users/robskrob/.rvm/rubies/ruby-2.4.1/lib/ruby/site_ruby/2.4.0/rubygems/core_ext/kernel_require.rb:55:in `require' from (irb):4 from /Users/robskrob/.rvm/rubies/ruby-2

Is /etc/irbrc installed by OS X? Does irb read it?

▼魔方 西西 提交于 2019-12-04 03:28:27
问题 While investigating an issue with irb on my Mac (OS X 10.11.5) I noticed /etc/irbrc . The first few lines follow: # Some default enhancements/settings for IRB, based on # http://wiki.rubygarden.org/Ruby/page/show/Irb/TipsAndTricks unless defined? ETC_IRBRC_LOADED # Require RubyGems by default. require 'rubygems' # Activate auto-completion. require 'irb/completion' # continued ... It seems to be out of date (rubygarden.org is gone, rubygems is in the standard library these days) and does

In IRB, can I view the source of a method I defined earlier?

这一生的挚爱 提交于 2019-12-04 00:51:58
If I define a method in IRB, is there any way to review its source later in the session? > def my_method > puts "hi" > end Several screens of output later I'd like to be able to write something like > source my_method and get back: => def my_method; puts "hi"; end; Is this possible? Serabe Try pry . There is a railscast about it (released this same week!) and it shows you how to show the code by using show-method . Not in IRB but in Pry this feature is built-in. Behold: pry(main)> def hello pry(main)* puts "hello my friend, it's a strange world we live in" pry(main)* puts "yes! the rich give

Accessing the irb in a modular Sinatra application

久未见 提交于 2019-12-03 21:35:21
I am building an application which subclasses Sinatra like so: require 'rubygems' require 'sinatra/base' require 'sinatra/assetpack' class App < Sinatra::Base ... run! end How can I access irb? Options are not parsed when executing sinatra this way, how do I programmatically open an irb shell? I'm a little confused whether you want to open an IRB session from within your app (?) or use IRB to debug your Sinatra project? For debugging Rack-based apps (such as Sinatra), I like using the racksh gem , which " is like script/console in Rails " for Rack applications. Its main advantage over IRB is

Explanation of Ruby code for building Trie data structures

血红的双手。 提交于 2019-12-03 14:34:14
So I have this ruby code I grabbed from wikipedia and I modified a bit: @trie = Hash.new() def build(str) node = @trie str.each_char { |ch| cur = ch prev_node = node node = node[cur] if node == nil prev_node[cur] = Hash.new() node = prev_node[cur] end } end build('dogs') puts @trie.inspect I first ran this on console irb, and each time I output node , it just keeps giving me an empty hash each time {} , but when I actually invoke that function build with parameter 'dogs' string, it actually does work, and outputs {"d"=>{"o"=>{"g"=>{"s"=>{}}}}} , which is totally correct. This is probably more

Unicode characters in Ruby 1.9.3 IRB with RVM

你离开我真会死。 提交于 2019-12-03 09:49:41
问题 Update : I found almost exact similar question, yet it has slightly different prerequisites and thus doesn't help much. Given: MacOS Lion 10.7.3 rvm 1.14.2 ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-darwin11.3.0] Ruby was installed with the following line: rvm install 1.9.3 --with-readline-dir=/usr/local/Cellar/readline/6.2.2/ When I fire up irb or rails c and start typing unicode characters, I get: \U+FFD0\U+FFBF\U+FFD1\U+FFD0\U+FFB8\U+FFD0\U+FFBC\U+FFD0\U+FFB5\U+FFD1 How do I get

Get all local variables or available methods from irb?

£可爱£侵袭症+ 提交于 2019-12-03 09:43:43
When I go into irb and type in a command that does not exist I get an error stating "undefined local variable or method 'my_method' for main:Object (NameError)" Is there a way to just get a list of what local variables or methods ARE available? This would be really useful for exploring ruby. Zabba Look for methods in the Kernel, Object and Module : e.g. local_variables , instance_methods , instance_variables . Other great methods in there. inspect is another one. Great answers. As you explore, you have these at your disposal: obj.private_methods obj.public_methods obj.protected_methods obj

Rails console - use image_tag method

心已入冬 提交于 2019-12-03 06:07:29
How can I execute a image_tag method in a Rails console Run the console $ rails c Load helpers include ActionView::Helpers Execute the command image_tag('test.png') I got a strange error. Please help! Not sure why you're getting that error. It is strange. But the Rails Console exposes the helper methods through the helper variable. So this should work: helper.image_tag('test.png') OK... I found the solution. The error is showing only in Rails 3 but I fixed it by setting the config.action_controller.asset_host = "http://..." config.action_mailer.asset_host = "http://..." in my environemnt file

Is there something like bpython for Ruby?

不羁岁月 提交于 2019-12-03 05:47:10
问题 IRb is pretty plain compared to bpython, even when using wirble. Is there any ruby equivalent of bpython? 回答1: Use Pry: http://pry.github.com It is written from scratch and let's you: view method source code view method documentation (not using RI so you dont have to pre-generate it) pop in and out of different contexts invoke at runtime, in any context syntax highlighting gist integration view and replay history open editors to edit method using edit-method obj.my_method syntax A tonne more

How do I introspect things in Ruby?

泪湿孤枕 提交于 2019-12-03 04:53:54
问题 For instance, in Python, I can do things like this if I want to get all attributes on an object: >>> import sys >>> dir(sys) ['__displayhook__', '__doc__', '__excepthook__', '__name__', '__package__', '__stderr__', '__stdin__', '__stdout__', '_clear_type_cache', '_current_frames', '_getframe', 'api_version', 'argv', 'builtin_module_names', 'byteorder', 'call_tracing', 'callstats', 'copyright', 'displayhook', 'dont_write_bytecode', 'exc_clear', 'exc_info', 'exc_type', 'excepthook', 'exec