Class: FIRM::Serializable::MethodResolver
- Inherits:
-
Object
- Object
- FIRM::Serializable::MethodResolver
- Defined in:
- lib/firm/serializable.rb
Overview
Small utility class for delayed method resolving
Instance Method Summary collapse
-
#initialize(klass, mtd_id, default = false) ⇒ MethodResolver
constructor
A new instance of MethodResolver.
- #resolve ⇒ Object
Constructor Details
#initialize(klass, mtd_id, default = false) ⇒ MethodResolver
Returns a new instance of MethodResolver.
604 605 606 607 608 |
# File 'lib/firm/serializable.rb', line 604 def initialize(klass, mtd_id, default=false) @klass = klass @mtd_id = mtd_id @default = default end |
Instance Method Details
#resolve ⇒ Object
610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 |
# File 'lib/firm/serializable.rb', line 610 def resolve m = @klass.instance_method(@mtd_id) rescue nil if m # check arity == 0 if m.arity>0 unless @default Kernel.raise ArgumentError, "Deserialize finalizer method #{@klass}#{@mtd_id} should not expect any argument", caller end else return ->(obj) { m.bind(obj).call } end end nil end |