Closed SaphMB closed 7 years ago
As I understand it, when you call an argument using the argument.method structure, this will only work if the object (that is the argument) is allowed to use that method. ie is this private method something which is in the scope of its class?
The error message you are getting is Ruby saying "fizbuzz isn't a method for 3 (which is an object of the Fixnum class).
To call the method like this you have to give the method to the class in question, and structure the method to use the "self" keyword, so:
class Fixnum
def fizzbuzz
puts "fizz" if self % 3 == 0
end
end
Thanks a lot Paul! That makes perfect sense!
Hi, when using the alternative version of the rspec test:
it 'returns "fizz" for the number 3' do expect(3.fizzbuzz).to eq 'fizz' end
I'm getting the below error:
Does anyone have any insight?