Module: JRuby::ScalaSupport::Common

Includes:
Enumerable
Included in:
Map::Common, Seq::Common, Set::Common, Tuple
Defined in:
lib/jruby/scala_support.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.fake_identity(target, pretended_klass) ⇒ Object

Fake target identity. This extends #is_a?, #kind_of?, #instance_of? on target and #=== on pretended_klass.

Example: fake_identity YourCustomHash, Hash

Beware that #<, #<= and #ancestors on target will still return that target is not pretended_klass.

Parameters:

  • target (Class)

    class that is being given fake identity

  • pretended_klass (Class)

    class that target is pretending to be



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/jruby/scala_support.rb', line 21

def self.fake_identity(target, pretended_klass)
  target.instance_eval do
    [:is_a?, :kind_of?, :instance_of?].each do |method|
      define_method(method) do |klass|
        klass == pretended_klass ? true : super(klass)
      end
    end
  end

  (class << pretended_klass; self; end).instance_eval do
    define_method(:===) do |object|
      if object.is_a?(target)
        true
      else
        super(object)
      end
    end
  end
end

Instance Method Details

#blank?Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/jruby/scala_support.rb', line 49

def blank?
  @raw.isEmpty
end

#initialize(raw) ⇒ Object



41
42
43
# File 'lib/jruby/scala_support.rb', line 41

def initialize(raw)
  @raw = raw
end

#scala_collectionObject



45
46
47
# File 'lib/jruby/scala_support.rb', line 45

def scala_collection
  @raw
end

#sizeObject



53
54
55
# File 'lib/jruby/scala_support.rb', line 53

def size
  @raw.size
end