Add a new method by add method to Class : Method Creation « Method « Ruby
- Ruby
- Method
- Method Creation
Add a new method by add method to Class
class String
def last(n)
self[-n, n]
end
end
p "Here's a string.".last(7) # => "string."
Related examples in the same category