Class: Nanoc3::Context
- Inherits:
-
Object
- Object
- Nanoc3::Context
- Defined in:
- lib/nanoc3/base/context.rb
Overview
Provides a context and a binding for use in filters such as the ERB and Haml ones.
Direct Known Subclasses
Instance Method Summary collapse
-
#get_binding ⇒ Binding
Returns a binding for this instance.
-
#initialize(hash) ⇒ Context
constructor
Creates a new context based off the contents of the hash.
Constructor Details
#initialize(hash) ⇒ Context
Creates a new context based off the contents of the hash.
Each pair in the hash will be converted to an instance variable and an instance method. For example, passing the hash ‘{ :foo => ’bar’ }‘ will cause `@foo` to have the value `“bar”`, and the instance method `#foo` to return the same value `“bar”`.
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/nanoc3/base/context.rb', line 28 def initialize(hash) hash.each_pair do |key, value| # Build instance variable instance_variable_set('@' + key.to_s, value) # Define method = (class << self ; self ; end) .send(:define_method, key) { value } end end |
Instance Method Details
#get_binding ⇒ Binding
Returns a binding for this instance.
42 43 44 |
# File 'lib/nanoc3/base/context.rb', line 42 def get_binding binding end |