Class: Code::Object::String

Inherits:
Code::Object show all
Defined in:
lib/code/object/string.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Code::Object

#<=>, #==, #[], #[]=, #falsy?, #hash, #key?, #truthy?

Constructor Details

#initialize(string) ⇒ String

Returns a new instance of String.



6
7
8
# File 'lib/code/object/string.rb', line 6

def initialize(string)
  @raw = string
end

Instance Attribute Details

#rawObject (readonly)

Returns the value of attribute raw.



4
5
6
# File 'lib/code/object/string.rb', line 4

def raw
  @raw
end

Instance Method Details

#call(**args) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/code/object/string.rb', line 10

def call(**args)
  operator = args.fetch(:operator, nil)
  arguments = args.fetch(:arguments, [])

  if operator == "to_function"
    to_function(arguments)
  elsif operator == "+"
    plus(arguments)
  elsif operator == "reverse"
    reverse(arguments)
  else
    super
  end
end

#inspectObject



37
38
39
# File 'lib/code/object/string.rb', line 37

def inspect
  raw.inspect
end

#succObject



25
26
27
# File 'lib/code/object/string.rb', line 25

def succ
  ::Code::Object::String.new(raw.succ)
end

#to_sObject



33
34
35
# File 'lib/code/object/string.rb', line 33

def to_s
  raw
end

#to_symObject



29
30
31
# File 'lib/code/object/string.rb', line 29

def to_sym
  raw.to_sym
end