Module: JactiveSupport::CoreExtensions::Enum

Included in:
String, Symbol
Defined in:
lib/jactive_support/core_ext/enum.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(other_mod) ⇒ Object



6
7
8
9
10
11
12
# File 'lib/jactive_support/core_ext/enum.rb', line 6

def self.included(other_mod)
  other_mod.send :alias_method, :flash_without_enum, :===
  other_mod.send :alias_method, :===, :flash_with_enum

  other_mod.send :alias_method, :to_java_without_enum, :to_java
  other_mod.send :alias_method, :to_java, :to_java_with_enum
end

Instance Method Details

#flash_with_enum(other) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/jactive_support/core_ext/enum.rb', line 14

def flash_with_enum(other)
  if other.java_kind_of? java::lang::Enum
    other.name == self.to_s || other.name == self.to_s.camelize
  else
    flash_without_enum(other)
  end
end

#to_java_with_enum(other = nil) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/jactive_support/core_ext/enum.rb', line 22

def to_java_with_enum(other=nil)
  if other.superclass == java::lang::Enum
    begin
      other.find_value_of(self)
    rescue java::lang::IllegalArgumentException => e
      raise TypeError, e.message
    end
  else
    to_java_without_enum(other)
  end
end