Class: Object

Inherits:
BasicObject
Defined in:
lib/object.rb

Class Method Summary collapse

Class Method Details

.comparable_by_alphabet(alphabet, &block) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
# File 'lib/object.rb', line 3

def self.comparable_by_alphabet(alphabet, &block)
  if block
    define_method :"<=>" do |other|
      block[self].to_s.compare_by_alphabet(block[other].to_s, alphabet)
    end
  else
    define_method :"<=>" do |other|
      self.to_s.compare_by_alphabet(other.to_s, alphabet)
    end
  end    
end