Class: String::Wrapper

Inherits:
Object
  • Object
show all
Defined in:
opal/opal/corelib/string/inheritance.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(string = '') ⇒ Wrapper

Returns a new instance of Wrapper



34
35
36
# File 'opal/opal/corelib/string/inheritance.rb', line 34

def initialize(string = '')
  @literal = string
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(*args, &block) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'opal/opal/corelib/string/inheritance.rb', line 38

def method_missing(*args, &block)
  result = @literal.__send__(*args, &block)

  if `result._isString != null`
    if `result == #@literal`
      self
    else
      self.class.allocate(result)
    end
  else
    result
  end
end

Class Method Details

.[](*objects) ⇒ Object



30
31
32
# File 'opal/opal/corelib/string/inheritance.rb', line 30

def self.[](*objects)
  allocate(objects)
end

.allocate(string = "") ⇒ Object



18
19
20
21
22
# File 'opal/opal/corelib/string/inheritance.rb', line 18

def self.allocate(string = "")
  obj = super()
  `obj.literal = string`
  obj
end

.new(*args, &block) ⇒ Object



24
25
26
27
28
# File 'opal/opal/corelib/string/inheritance.rb', line 24

def self.new(*args, &block)
  obj = allocate
  obj.initialize(*args, &block)
  obj
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?, ===



60
61
62
# File 'opal/opal/corelib/string/inheritance.rb', line 60

def ==(other)
  @literal == other
end

#initialize_copy(other) ⇒ Object



52
53
54
# File 'opal/opal/corelib/string/inheritance.rb', line 52

def initialize_copy(other)
  @literal = `other.literal`.clone
end

#inspectObject



75
76
77
# File 'opal/opal/corelib/string/inheritance.rb', line 75

def inspect
  @literal.inspect
end

#respond_to?(name) ⇒ Boolean

Returns:



56
57
58
# File 'opal/opal/corelib/string/inheritance.rb', line 56

def respond_to?(name, *)
  super || @literal.respond_to?(name)
end

#to_sObject



67
68
69
# File 'opal/opal/corelib/string/inheritance.rb', line 67

def to_s
  @literal
end

#to_strObject



71
72
73
# File 'opal/opal/corelib/string/inheritance.rb', line 71

def to_str
  self
end