Class: Tsundere::Imouto
- Inherits:
-
Object
- Object
- Tsundere::Imouto
- Defined in:
- lib/tsundere/imouto.rb
Instance Method Summary collapse
-
#initialize(parent, level) ⇒ Imouto
constructor
A new instance of Imouto.
-
#method_missing(meth, *args, &block) ⇒ Object
initialize.
-
#respond_to?(meth) ⇒ Boolean
method_missing.
Constructor Details
#initialize(parent, level) ⇒ Imouto
Returns a new instance of Imouto.
5 6 7 8 |
# File 'lib/tsundere/imouto.rb', line 5 def initialize parent, level @parent = parent @level = level end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, *args, &block) ⇒ Object
initialize
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/tsundere/imouto.rb', line 10 def method_missing meth, *args, &block conditions = [] conditions << lambda do :[] == meth and @parent.dere_for? @level, process_args( *args ) end conditions << lambda do :[]= == meth and @parent.dere_for? @level, process_args( *args[0..-2] ) end conditions << lambda do @parent.dere_for? @level, meth end if @parent.respond_to? meth if conditions.inject(false) { |mem, c| mem or c.call } case meth when :[] @parent[*args, &block] unless block.nil? @parent[*args] if block.nil? when :[]= tail = args.pop @parent[*args] = tail else @parent.send(meth, *args, &block) unless block.nil? @parent.send(meth, *args) if block.nil? end # meth else return @parent.tsun_for @level end # if conditions inject else super end # if has method end |
Instance Method Details
#respond_to?(meth) ⇒ Boolean
method_missing
45 46 47 48 49 50 51 52 53 |
# File 'lib/tsundere/imouto.rb', line 45 def respond_to? meth if @parent.dere_for? @level, meth @parent.respond_to? meth elsif :[] == meth or :[]= == meth @parent.respond_to? meth else false end # if-dere end |