lib/surrogate/values.rb in surrogate-0.8.0 vs lib/surrogate/values.rb in surrogate-0.8.1

- old
+ new

@@ -4,11 +4,13 @@ # in an instance variable on a surrogate, intended to be returned by an api method class Value # convert raw arguments into a value def self.factory(*args, &block) arg = args.first - if args.size > 1 + if block + BlockValue.new &block + elsif args.size > 1 ValueQueue.new args elsif arg.kind_of? Exception Raisable.new arg elsif arg.kind_of? BaseValue arg @@ -31,9 +33,19 @@ def factory(*args, &block) Value.factory(*args, &block) end end + + class BlockValue < BaseValue + def initialize(&block) + @block = block + end + + def value(method_name) + @block.call + end + end class Raisable < BaseValue def value(*) raise @value end