I have the following code:
<%= "#{@resource.first_name.capitalize} " + "#{@resource.last_name.capitalize}" + "'s Area" %>
which prints stuff like:
Tom Byrne's Area, or Mark Kelly's Area
It would be really cool though if I could avoid things like:
Jean Collins's Area, or Paul Harris's Area
and use the correct grammar like:
Jean Collins' Area, or Paul Harris' Area
Anybody know how I could write some code that would write "'s Area" if the last letter of last_name is not "s", and write "' Area" if it is "s"?
To get the last character of a string: str[-1].
You might look if someone else has done this, since there are several special cases. A quick google search yielded the possessive gem.
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