I work with ActiveAttr, which gives you the ability to initialize through a block:
person = Person.new() do |p|
p.first_name = 'test'
p.last_name = 'man'
end
However, in a specific class that includes ActiveAttr :: Model, I want to get around this function, since I want to use a block for something else. So, let's go:
class Imperator::Command
include ActiveAttr::Model
end
class MyCommand < Imperator::Command
def initialize(*args, &block)
@my_block = block
super(*args)
end
end
This fails because the block still goes through the chain and, ultimately, inside ActiveAttr, this code runs:
def initialize(*)
super
yield self if block_given?
end
So, if my call looks like this:
MyCommand.new() { |date| date.advance(month: 1) }
It does not work as follows:
NoMethodError: undefined method `advance' for #<MyCommand:0x007fe432c4fb80>
since MyCommand does not have a method: redirect it so that the call to MyCommand obviously fails.
So my question is, is there a way to remove a block from a method signature before I call again superso that the block moves no further than my overridden initializer?