ruby’s last character in a String

# returns the character code
# I don't know how to translate this back to a String
irb(main):002:0> "bar"[-1]
=> 114

# This works but reads a little awkward
irb(main):001:0> "bar"[-1..-1]
=> "r"


Leave a Reply

Formatting: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>