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

Constructor Details

#initialize(*args) ⇒ Right

Returns a new instance of Right.



34
35
36
37
# File 'lib/dentaku/ast/functions/string_functions.rb', line 34

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

Instance Method Details

#value(context = {}) ⇒ Object



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

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