Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

why does irb freak out sometimes when I paste in a script?

Tags:

ruby

irb

def load_lib
    path = File.join(File.dirname(__FILE__), 'lib')
    failures = []
    Dir.glob("#{path}/**/*.rb").each {  |file|
        puts "loading: #{file} ... "
    }
end 

There's the script. When I put each line in individually, the load_lib function is available and works fine. But when I paste it into irb in one big chunk (Ubuntu terminal, Sh Ctrl C) it freaks out at the Dir.glob(... line and shows this:

Display all 931 possibilities? (y or n)
!
!=
!~
<=>
.... [dozens of lines in this vein]

and then the method isn't created at all.

Here's what happens (success) when I paste it in one line at a time:

>>  def load_lib
>>     path = File.join(File.dirname(__FILE__), 'lib')
>>     failures = []
>> Dir.glob("#{path}/**/*.rb").each {  |file|
?> puts file
>> }
>> end
=> nil
>> load_lib
./lib/alpha_processor.rb
./lib/development_mail_interceptor.rb
./lib/service_processors/beta_processor.rb

Is there something about the [] or {} that irb doesn't like when they are pasted in?

like image 414
jcollum Avatar asked Jan 18 '12 19:01

jcollum


1 Answers

That's because of TAB characters you have in your source file. Indent with spaces. :-)

like image 169
Sergio Tulentsev Avatar answered Nov 03 '22 15:11

Sergio Tulentsev