Class: Code::Object::String
Instance Attribute Summary collapse
Instance Method Summary
collapse
#<=>, #==, #falsy?, #hash, #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
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
26
27
28
29
30
31
|
# File 'lib/code/object/string.rb', line 10
def call(**args)
operator = args.fetch(:operator, nil)
arguments = args.fetch(:arguments, [])
globals = multi_fetch(args, *::Code::GLOBALS)
value = arguments.first&.value
if operator == "&" || operator == "to_function"
sig(arguments)
to_function(**globals)
elsif operator == "+"
sig(arguments) { ::Code::Object }
plus(value)
elsif operator == "*"
sig(arguments) { ::Code::Object::Number }
multiplication(value)
elsif operator == "reverse"
sig(arguments)
reverse
else
super
end
end
|
45
46
47
|
# File 'lib/code/object/string.rb', line 45
def inspect
raw.inspect
end
|
33
34
35
|
# File 'lib/code/object/string.rb', line 33
def succ
::Code::Object::String.new(raw.succ)
end
|
41
42
43
|
# File 'lib/code/object/string.rb', line 41
def to_s
raw
end
|
37
38
39
|
# File 'lib/code/object/string.rb', line 37
def to_sym
raw.to_sym
end
|