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

#raw ⇒ Object (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
24
25
# 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 == "*"
    multiplication(arguments)
  elsif operator == "reverse"
    reverse(arguments)
  else
    super
  end
end

#inspect ⇒ Object



39
40
41
# File 'lib/code/object/string.rb', line 39

def inspect
  raw.inspect
end

#succ ⇒ Object



27
28
29
# File 'lib/code/object/string.rb', line 27

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

#to_s ⇒ Object



35
36
37
# File 'lib/code/object/string.rb', line 35

def to_s
  raw
end

#to_sym ⇒ Object



31
32
33
# File 'lib/code/object/string.rb', line 31

def to_sym
  raw.to_sym
end