Running -r in IRB



After doing a couple of websites using Rails, I realized that my problem
is that I am terrible at ruby so I bought "Ruby by Example" by Kevin
Baird and started on page 1.

I'm at the part in chapter 2 where I am being instructed to run -r in
irb to include a required class file and I'm getting the following
error:

irb(main):001:0> -r 99bottles.rb
SyntaxError: compile error
(irb):1: syntax error, unexpected tINTEGER, expecting kDO or '{' or '('
-r 99bottles.rb
^
from (irb):1

When I run the file 99bottles.rb from the command prompt it doesn't do
anything but gives me no errors. I believe that since the file creates a
new class, the book wants me to require the file so I can run new
commands against the new class in the 99bottles.rb file.

I am including the contents of the 99bottles.rb file as well...If anyone
can help point me in the right direction with including a class into irb
using -r with this file, I would be very grateful.

thanks
jackster

-------------------------99bottles.rb--------------------------
#!/usr/bin/env ruby
# 99 bottles problem in Ruby

class Wall

def initialize(num_of_bottles)
@bottles = num_of_bottles
end

=begin rdoc
Predicate, ends in a question mark, returns <b>Boolean</b>.
=end
def empty?()
@bottles.zero?
end

def sing_one_verse!()
puts sing(' on the wall, ') + sing("\n") + take_one_down! + sing("
on the wall.\n\n")
end

private

def sing(extra='')
"#{(@bottles > 0) ? @bottles : 'no more'} #{(@bottles == 1) ?
'bottle' : 'bottles'} of beer" + extra
end

=begin rdoc
Destructive method named with a bang because it decrements @bottles.
Returns a <b>String</b>.
=end
def take_one_down!()
@bottles -= 1
'take one down, pass it around, '
end

end
--
Posted via http://www.ruby-forum.com/.

.



Relevant Pages

  • Re: [SOLUTION] Code to S-Exp (#95)
    ... Please do not post any solutions or spoiler discussion for this quiz until ... Support Ruby Quiz by submitting ideas as often as you can: ... An s-expression is a nested list structure where the first element of each list ... def method_missing ...
    (comp.lang.ruby)
  • Re: [SOLUTION] Code to S-Exp (#95)
    ... Please do not post any solutions or spoiler discussion for this quiz until ... Support Ruby Quiz by submitting ideas as often as you can: ... An s-expression is a nested list structure where the first element of each list ... def method_missing ...
    (comp.lang.ruby)
  • Re: How to access to local variables in enclosing scopes?
    ... Ruby really seems ... all mutation methods of a class for some purpose (e.g. making a read- ... def singleton_method ... interface to singleton behavior that you need. ...
    (comp.lang.ruby)
  • [ANN] attributes-5.0.0
    ... metakoans.rb ruby quiz ... module MigrationDSL ... def migration_class ... ~> cat samples/a.rb ...
    (comp.lang.ruby)
  • Re: Dynamic stuff and books
    ... whether it's implemented in Ruby or C: ... def foo ... And so I think I found a really important use for singleton methods, ...
    (comp.lang.ruby)