I am wondering if there is a method in Ruby to turn a word such as month
to monthly
.
Similar to pluralize(word)
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.
Thus, 'from' is a preposition that can, at times, begin an adverbial phrase.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With