Class: Lich::Common::StringProc
- Inherits:
-
Object
- Object
- Lich::Common::StringProc
- Defined in:
- documented/common/class_exts/stringproc.rb
Overview
Represents a String processing utility that evaluates a string as Ruby code. This class allows for the creation of callable objects that can execute Ruby code contained in a string.
Class Method Summary collapse
-
._load(string) ⇒ StringProc
Loads a StringProc object from a string representation.
Instance Method Summary collapse
-
#_dump(_d = nil) ⇒ String
Dumps the string representation of the object.
-
#call(*_a) ⇒ Object
Executes the Ruby code contained in the string.
-
#class ⇒ Class
Returns the class of the object.
-
#initialize(string) ⇒ StringProc
constructor
Initializes a new StringProc instance.
-
#inspect ⇒ String
Returns a string representation of the StringProc object.
-
#kind_of?(type) ⇒ Boolean
Checks if the object is of a certain type.
-
#to_json(*args) ⇒ String
Converts the StringProc object to JSON format.
Constructor Details
#initialize(string) ⇒ StringProc
Initializes a new StringProc instance.
15 16 17 |
# File 'documented/common/class_exts/stringproc.rb', line 15 def initialize(string) @string = string end |
Class Method Details
._load(string) ⇒ StringProc
Loads a StringProc object from a string representation.
69 70 71 |
# File 'documented/common/class_exts/stringproc.rb', line 69 def StringProc._load(string) StringProc.new(string) end |
Instance Method Details
#_dump(_d = nil) ⇒ String
Dumps the string representation of the object.
45 46 47 |
# File 'documented/common/class_exts/stringproc.rb', line 45 def _dump(_d = nil) @string end |
#call(*_a) ⇒ Object
Executes the Ruby code contained in the string.
38 39 40 |
# File 'documented/common/class_exts/stringproc.rb', line 38 def call(*_a) proc { eval(@string) }.call end |
#class ⇒ Class
Returns the class of the object.
30 31 32 |
# File 'documented/common/class_exts/stringproc.rb', line 30 def class Proc end |
#inspect ⇒ String
Returns a string representation of the StringProc object.
53 54 55 |
# File 'documented/common/class_exts/stringproc.rb', line 53 def inspect "StringProc.new(#{@string.inspect})" end |
#kind_of?(type) ⇒ Boolean
Checks if the object is of a certain type.
24 25 26 |
# File 'documented/common/class_exts/stringproc.rb', line 24 def kind_of?(type) Proc.new {}.kind_of? type end |
#to_json(*args) ⇒ String
Converts the StringProc object to JSON format.
62 63 64 |
# File 'documented/common/class_exts/stringproc.rb', line 62 def to_json(*args) ";e #{_dump}".to_json(args) end |