Interpolation & string upcase

Hi all,

I’m new to Ruby and slowly learning the ropes, I have been spending hours in the last few days trying to catch up and I’m really not getting this (I’m sure it is obvious!)

I can easily output “My Name” using .upcase but it keeps throwing up issues and wont allow me to move on to the next challenge - any tips there would be helpful.

my_name = “Jordan”

Please write your code below this line…

…and above this line.

puts “My name is #{upper(my_name)}”

"Write a method called upper that will output Jordan all in upper case.

Note that we’re passing the variable my_name as argument when we’re calling the method, that should give you a hint on what you need to include. Please don’t change any of our code, you can only write new code or reuse previous code.

Your output should read as below :

My name is JORDAN

Your method should be a template - this can then be used for any variables that are passed through it.

We know that a method will take this basic form…

def method
  # code

We add a parameter list to take any inputs…

def method(param)
  # code

Now we have to decide what our method will be doing so we can name it accordingly and set up the operational code. Your method will be named, upper and will take one parameter, a String type. You already know the Ruby built-in, upcase so all you need to do is write an expression in your method and return it.

Note that Ruby automatically treats the last line of a method as an implicit return so that keyword is not needed.


hmm, still no joy with this, I think i’ve tried everything (known to me) it just comes up with errors.

Please post a link to the exercise so we can have a look. Thanks.

Does your method look something like this?

def upper(str)

the full code looks like this:

my_name = "Jordan"

# Please write your code below this line...
def upper(
# ...and above this line.

puts "My name is #{upper(my_name)}"

I can only type method on line 4, no amendments to any other lines
(my_name = Jordan) starts on line one

the requirements are : Please don’t change any of our code, you can only write new code or reuse previous code.


Where is the rest of your method code?

def upper (my_name) was my last try

I different ways to do this including having .upcase. the process states I cannot use other lines…I’m out of options, I really don’t know what to try next other than ignore the requirements and write my own code.

We could still use a link to that exercise…

I’ve figured it out! - probably my faulty staring at the screen too long and the answer was glaring back at me! thanks for your help

can u show the code that you used here?

What are you stuck on?

I figured it out but I’m stuck on this following bit.

The code I have done so far:
name = “Jordan”

def upper(string)

def lower(string)

def random_name
[“Ollie”, “Ana”].sample

def random_case(string)
[upper(string), lower(string)].sample

Please write your code between this line…

… and this line

puts “My name is #{random_both()}”

In the section where I have to write my code, I need the code to generate the names Ana and Ollie at random, and also their first letter needs be upper/lowercase at random.

I have tried several ways and I keep getting it wrong.


We don’t see that method defined in your code.

It has been given to me, I have to use that to create the code for the final line
puts “My name is #{random_both()}”.

I am stuck on creating that. This is what I tried.

def random_both()
[random_name, random_case(string)].sample

I can’t figure out what needs to change.


Is this meant to be a random sample or just the two other random values?

Hello! As well as the prompt by ~mtf, in your array, you have the random_case(string) function-and it takes the argument string. Yet where is that argument coming from?

Random sample so, the final output can be any of the following:

‘My name is OLLIE’


‘My name is ollie’


“My name is ANA”


“My name is ana”

Could you not just combine the method calls?


Hey it worked. Thanks.

why didn’t this work [random_name, random_case(string)].sample, but that did? please explain.

thanks again.

Because as @codeneutrino pointed out, string is undefined. We defined it with the call to random_name(), which returns a random string. We can then pass that return value to the random_case() method which returns the random case.

Your approach was loading an array with two already random values and picking one or the other value. The logic is flawed.