I am new to Ruby on Rails. Can some one please help me with this question?How would you modify the following to be consistent with Ruby's style?class Add_dashdef dashesHere(word)    attachTheDashes = -- + word + --        return attachTheDashes   endend
Ruby function to surround a word with dashes
beginner;strings;ruby;ruby on rails
Well first your indention is a bit strange, it'd be better like this:class Add_dash  def dashesHere(word)    attachTheDashes = -- + word + --    return attachTheDashes  endendAnd 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 + --  endendBut 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}--  endendAnd 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}--  endendI hope this helps!