Class: Dentaku::AST::StringFunctions::Right

Inherits:
Base show all
Defined in:
lib/dentaku/ast/functions/string_functions.rb

Constant Summary

Constants inherited from Function

Function::DIG

Instance Method Summary collapse

Methods inherited from Base

#negative_argument_failure, #type

Methods inherited from Function

#dependencies, get, numeric, register, register_class, registry

Methods inherited from Node

arity, #dependencies, peek, precedence, #type

Constructor Details

#initialize(*args) ⇒ Right

Returns a new instance of Right.



42
43
44
45
# File 'lib/dentaku/ast/functions/string_functions.rb', line 42

def initialize(*args)
  super
  @string, @length = *@args
end

Instance Method Details

#value(context = {}) ⇒ Object



47
48
49
50
51
52
# File 'lib/dentaku/ast/functions/string_functions.rb', line 47

def value(context = {})
  string = @string.value(context).to_s
  length = @length.value(context)
  negative_argument_failure('RIGHT') if length < 0
  string[length * -1, length] || string
end