lib/hotcell/manipulator.rb in hotcell-0.1.0 vs lib/hotcell/manipulator.rb in hotcell-0.2.0
- old
+ new
@@ -5,20 +5,38 @@
included do
class_attribute :manipulator_methods, instance_writter: false
self.manipulator_methods = Set.new
- def self.manipulator *methods
+ def self.manipulate *methods
self.manipulator_methods = Set.new(manipulator_methods.to_a + methods.flatten.map(&:to_s))
end
end
def to_manipulator
self
end
def manipulator_invoke method, *arguments
- send(method, *arguments) if manipulator_methods.include? method
+ if method == '[]'
+ manipulator_invoke_brackets *arguments
+ elsif manipulator_invokable? method
+ send(method, *arguments)
+ end
+ end
+
+ private
+
+ def manipulator_invokable? method
+ manipulator_methods.include? method
+ end
+
+ def manipulator_invoke_brackets *arguments
+ if respond_to? :[]
+ self[*arguments]
+ else
+ manipulator_invoke *arguments
+ end
end
end
include Mixin