Class: Lich::Common::StringProc

Inherits:
Object
  • Object
show all
Defined in:
documented/common/class_exts/stringproc.rb

Overview

Represents a processor for string evaluations.

This class allows for the evaluation of a string as Ruby code.

See Also:

Instance Method Summary collapse

Constructor Details

#initialize(string) ⇒ StringProc

Initializes a new StringProc instance.

Parameters:

  • string (String)

    the string to be processed



12
13
14
# File 'documented/common/class_exts/stringproc.rb', line 12

def initialize(string)
  @string = string
end

Instance Method Details

#_dump(_d = nil) ⇒ Object



36
37
38
# File 'documented/common/class_exts/stringproc.rb', line 36

def _dump(_d = nil)
  @string
end

#call(*_a) ⇒ Object

Evaluates the stored string as Ruby code.

Parameters:

  • args (Array)

    optional arguments for the evaluation

Returns:

  • (Object)

    the result of the evaluated string



32
33
34
# File 'documented/common/class_exts/stringproc.rb', line 32

def call(*_a)
  proc { eval(@string) }.call
end

#classClass

Returns the class of the object.

Returns:

  • (Class)

    the Proc class



25
26
27
# File 'documented/common/class_exts/stringproc.rb', line 25

def class
  Proc
end

#inspectString

Returns a string representation of the StringProc instance.

Returns:

  • (String)

    a string describing the StringProc instance



42
43
44
# File 'documented/common/class_exts/stringproc.rb', line 42

def inspect
  "StringProc.new(#{@string.inspect})"
end

#kind_of?(type) ⇒ Boolean

Checks if the object is of a given type.

Parameters:

  • type (Class)

    the class to check against

Returns:

  • (Boolean)

    true if the object is of the specified type



19
20
21
# File 'documented/common/class_exts/stringproc.rb', line 19

def kind_of?(type)
  Proc.new {}.kind_of? type
end

#to_json(*args) ⇒ String

Converts the StringProc instance to JSON format.

Parameters:

  • args (Array)

    optional arguments for JSON conversion

Returns:

  • (String)

    the JSON representation of the StringProc



49
50
51
# File 'documented/common/class_exts/stringproc.rb', line 49

def to_json(*args)
  ";e #{_dump}".to_json(args)
end