Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to return the adverbial form of the word

I am wondering if there is a method in Ruby to turn a word such as month to monthly.

Similar to pluralize(word)

like image 711
deb Avatar asked May 04 '11 15:05

deb


People also ask

What is the adverb form of good?

The rule of thumb is that good is an adjective and well is an adverb. Good modifies a noun; something can be or seem good. Well modifies a verb; an action can be done well.

Is from an adverb?

Thus, 'from' is a preposition that can, at times, begin an adverbial phrase.


1 Answers

I don't think there is any built in method, but you could write a simple one yourself:

CONSONANTS = [ 'b', 'c', 'd', 'f', 'g', 'h', 'j', 'k', 'l', 'm', 'n', 'p', 'q', 'r', 's', 't', 'v', 'w', 'x', 'y', 'z' ]

def adverbize(word)
  if word[-2,2] == "ly"
     word
  elsif word.length <= 3 and word[-1] == "y"
    word + "ly"
  elsif word[-2,2] == "ll"
     word + "y"
  elsif CONSONANTS.include? word[-3] and word[-2,2] == "le"
     word.sub(/e$/, "y")
  elsif word[-1] == "y"
     word.chop + "ily"
  else
     word + "ly"
  end
end

Another way to do this, that will work every time (this is mostly a joke, but you can use it if you'd like)

def adverbize(word)
    "In a " + word + " fashion."
end
like image 118
Mark Szymanski Avatar answered Oct 09 '22 11:10

Mark Szymanski