Class: Pakman::Ctx
- Inherits:
-
Object
- Object
- Pakman::Ctx
- Defined in:
- lib/pakman/cli/ctx.rb
Overview
Context
Instance Method Summary collapse
- #ctx ⇒ Object
-
#initialize(hash) ⇒ Ctx
constructor
A new instance of Ctx.
- #method_missing(mn, *args, &blk) ⇒ Object
Constructor Details
#initialize(hash) ⇒ Ctx
Returns a new instance of Ctx.
7 8 9 |
# File 'lib/pakman/cli/ctx.rb', line 7 def initialize( hash ) @hash = hash end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(mn, *args, &blk) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/pakman/cli/ctx.rb', line 16 def method_missing( mn, *args, &blk ) ## only allow read-only access (no arguments) if args.length > 0 # || mn[-1].chr == "=" return super # super( mn, *args, &blk ) end key = mn.to_s if @hash.has_key?( key ) puts "calling ctx.#{key}" value = @hash[ key ] puts " returning #{value.class.name}:" pp value value else puts "*** warning: ctx.#{key} missing" super end end |
Instance Method Details
#ctx ⇒ Object
11 12 13 14 |
# File 'lib/pakman/cli/ctx.rb', line 11 def ctx ### todo: check if method_missing works with binding in erb??? binding end |