Well first your indention is a bit strange, it'd be better like this:
class Add_dash
def dashesHere(word)
attachTheDashes = "--" + word + "--"
return attachTheDashes
end
end
And you typically don't need return
in Ruby, it'll return the last value evaluated in your function. So having that in mind you could write it like this:
class Add_dash
def dashesHere(word)
"--" + word + "--"
end
end
But Ruby also offers a way to easily put any value into a string, without adding a bunch of strings together. It really allows you to put any Ruby code in a string, and whatever it returns, will be put into your string. That looks like this: "math: #{1 + 1}"
which would be "math: 2", or "Hello #{name}"
would greet who ever was in name
.
So you could write your whole thing like this:
class Add_dash
def dashesHere(word)
"--#{word}--"
end
end
And in Ruby class names (Add_dash
in your case) are supposed to be written in CamelCase starting with a capital letter. Method names and everything else are written in snake_case.
This would be my final version:
class AddDash
def dashes_here(word)
"--#{word}--"
end
end
I hope this helps!