Class: Lich::Common::StringProc
- Inherits:
-
Object
- Object
- Lich::Common::StringProc
- Defined in:
- lib/common/class_exts/stringproc.rb
Overview
A class that processes strings as Ruby code.
Class Method Summary collapse
-
._load(string) ⇒ StringProc
Loads a StringProc object from a string.
Instance Method Summary collapse
-
#_dump(_d = nil) ⇒ String
Dumps the string representation of the object.
-
#call(*_a) ⇒ Object
Calls the stored string as Ruby code.
-
#class ⇒ Class
Returns the class of the current object.
-
#initialize(string) ⇒ StringProc
constructor
Initializes a new StringProc instance with the given string.
-
#inspect ⇒ String
Returns a string representation of the StringProc object.
-
#kind_of?(type) ⇒ Boolean
Checks if the current object is of the specified type.
-
#to_json(*args) ⇒ String
Converts the StringProc object to JSON format.
Constructor Details
#initialize(string) ⇒ StringProc
Initializes a new StringProc instance with the given string.
11 12 13 |
# File 'lib/common/class_exts/stringproc.rb', line 11 def initialize(string) @string = string end |
Class Method Details
._load(string) ⇒ StringProc
Loads a StringProc object from a string.
75 76 77 |
# File 'lib/common/class_exts/stringproc.rb', line 75 def StringProc._load(string) StringProc.new(string) end |
Instance Method Details
#_dump(_d = nil) ⇒ String
Dumps the string representation of the object.
46 47 48 |
# File 'lib/common/class_exts/stringproc.rb', line 46 def _dump(_d = nil) @string end |
#call(*_a) ⇒ Object
Calls the stored string as Ruby code.
38 39 40 |
# File 'lib/common/class_exts/stringproc.rb', line 38 def call(*_a) proc { eval(@string) }.call end |
#class ⇒ Class
Returns the class of the current object.
26 27 28 |
# File 'lib/common/class_exts/stringproc.rb', line 26 def class Proc end |
#inspect ⇒ String
Returns a string representation of the StringProc object.
53 54 55 |
# File 'lib/common/class_exts/stringproc.rb', line 53 def inspect "StringProc.new(#{@string.inspect})" end |
#kind_of?(type) ⇒ Boolean
Checks if the current object is of the specified type.
19 20 21 |
# File 'lib/common/class_exts/stringproc.rb', line 19 def kind_of?(type) Proc.new {}.kind_of? type end |
#to_json(*args) ⇒ String
Converts the StringProc object to JSON format.
64 65 66 |
# File 'lib/common/class_exts/stringproc.rb', line 64 def to_json(*args) ";e #{_dump}".to_json(args) end |