Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Numeric
- @@currencies = {'dollar' => 1, 'yen' => 0.013, 'euro' => 1.292, 'rupee' => 0.019}
- def method_missing(method_id)
- singular_currency = method_id.to_s.gsub( /s$/, '')
- if @@currencies.has_key?(singular_currency)
- self * @@currencies[singular_currency]
- else
- super
- end
- end
- def in(cur)
- singular_currency = cur.to_s.gsub(/s$/, '')
- self / @@currencies[singular_currency]
- end
- end
- def add_method(c, m, &b)
- c.class_eval {
- define_method(m, &b)
- }
- end
- add_method(String, :palindrome?) { self.to_s.gsub(/([-.,\s'!:~?])/, '').reverse.downcase == self.to_s.gsub(/([-.,\s'!~:?])/, '').downcase }
- module Enumerable
- def palindrome?
- if self.is_a?(Hash)
- false
- else
- self.to_a.join('').gsub(/([-.,\s'!:~?])/, '').reverse.downcase == self.to_a.join('').gsub(/([-.,\s'!~:?])/, '').downcase
- end
- end
- end
- puts (1..1).palindrome?
- puts "fooof".palindrome?
- puts ['1', '2', '1'].palindrome?
Add Comment
Please, Sign In to add comment