Why do i get the error "undefined method `upcase' for 2:Fixnum"?


#1

link: https://www.codecademy.com/courses/learn-ruby/lessons/introduction-to-ruby/exercises/strings-and-string-methods
<In what way does your code behave incorrectly? Include ALL error messages.>
as in the title, i get the error “undefined method `upcase’ for 2:Fixnum” for my code shown below.

```

name = “me”.length.upcase.reverse
puts name


#2

You call length on the string “me” Which gives you the fixnum 2.
You then try to call upcase on the integer 2. Numbers don’t have an upcase method. They don’t know how to be capital.


#3

String#length returns a Fixnum, and there is no method Fixnum#upcase.

This is not surprising: “me”.length equals to the Fixnum 2, and what
should be the upcase version of 2?

Ronald


#4

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.