Senthil Kumaran
Senthil Kumaran

Reputation: 56861

Ruby Docs Mixin Example - Wrong number of Arguments

ruby-docs.org tutorial has section on Modules where the concept of Mixins are introduced. The example given references the first argument as a string and prints it. But I see in the code that there is no receiver for the argument and execution does fail with ArgumentError

# Ruby module Mixin example.

module Debug
  def whoAmI?
    "#{self.type.name} (\##{self.id}): #{self.to_s}"
  end
end
class Phonograph
  include Debug
  # ...
end
class EightTrack
  include Debug
  # ...
end
ph = Phonograph.new("West End Blues")
et = EightTrack.new("Surrealistic Pillow")
ph.whoAmI? #»   "Phonograph (#537766170): West End Blues"
et.whoAmI? #»   "EightTrack (#537765860): Surrealistic Pillow"

My question is what is proper way to fix this code? Also, if someone can enlighten, how come the example in tutorial is wrong. Did anything change between the versions of ruby?

[tw-mbp13-skumaran ruby]$ ruby ruby23.rb ruby23.rb:16:in initialize': wrong number of arguments (1 for 0) (ArgumentError) from ruby23.rb:16:innew' from ruby23.rb:16

Upvotes: 0

Views: 168

Answers (1)

phaedryx
phaedryx

Reputation: 2054

The # ... indicates several missing methods in the code. Try this: https://gist.github.com/3353490

Upvotes: 1

Related Questions