Class: Viewlet::Base
- Inherits:
-
Object
- Object
- Viewlet::Base
- Defined in:
- lib/viewlet/base.rb
Instance Method Summary collapse
-
#initialize(name, view) ⇒ Base
constructor
A new instance of Base.
- #render ⇒ Object
Constructor Details
#initialize(name, view) ⇒ Base
Returns a new instance of Base.
5 6 7 8 9 10 11 12 |
# File 'lib/viewlet/base.rb', line 5 def initialize(name, view) @name = name @view = view @variables = { @name.to_sym => self, :unique_id => "viewlet_#{rand(36**20).to_s(36)}" } end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(variable_name, *args, &block) ⇒ Object (private)
20 21 22 23 24 25 26 27 28 |
# File 'lib/viewlet/base.rb', line 20 def method_missing(variable_name, *args, &block) is_write_op = if @variables[variable_name].is_a?(Proc) block.present? else args.any? || block.present? end send("_#{is_write_op ? :write : :read}_variable", variable_name, *args, &block) end |