Class: Memorium::Memo::Template
- Inherits:
-
Object
- Object
- Memorium::Memo::Template
- Defined in:
- lib/memorium/memo/template.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
Instance Method Summary collapse
-
#initialize(name, params) ⇒ Template
constructor
A new instance of Template.
- #reader_memoize_nil ⇒ Object
- #reader_plain ⇒ Object
- #result ⇒ Object
- #writer ⇒ Object
Constructor Details
#initialize(name, params) ⇒ Template
Returns a new instance of Template.
4 5 6 7 8 9 |
# File 'lib/memorium/memo/template.rb', line 4 def initialize(name, params) @name = name @params = params @result = [] end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
2 3 4 |
# File 'lib/memorium/memo/template.rb', line 2 def name @name end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
2 3 4 |
# File 'lib/memorium/memo/template.rb', line 2 def params @params end |
Instance Method Details
#reader_memoize_nil ⇒ Object
22 23 24 25 26 27 28 29 30 |
# File 'lib/memorium/memo/template.rb', line 22 def reader_memoize_nil @result << <<~RUBY def #{name.original}(#{params.signature}) return #{name.pure_memoized} if defined?(#{name.pure_memoized}) #{name.pure_memoized} = #{name.memoized}(#{params.parametrize}) end RUBY end |
#reader_plain ⇒ Object
13 14 15 16 17 18 19 20 |
# File 'lib/memorium/memo/template.rb', line 13 def reader_plain @result << <<~RUBY def #{name.original}(#{params.signature}) #{name.pure_memoized} ||= #{name.memoized}(#{params.parametrize}) end RUBY end |
#result ⇒ Object
11 |
# File 'lib/memorium/memo/template.rb', line 11 def result = @result.join("\n") |
#writer ⇒ Object
32 33 34 35 36 37 38 39 |
# File 'lib/memorium/memo/template.rb', line 32 def writer @result << <<~RUBY def #{name.setter}(value) #{name.pure_memoized} = value end RUBY end |