Wow, didn't know that! Makes sense. Thanks for explaining. - Aryk
On Wednesday, June 14, 2017 at 8:09:36 AM UTC-7, Jeremy Evans wrote:
>
> On Wednesday, June 14, 2017 at 7:15:29 AM UTC-7, Aryk Grosz wrote:
>>
>> If you do use dataset_module with a block I don't think it is actually
>> including the contents.
>>
>> Looking at the function:
>>
>> def dataset_module(mod = nil)
>> if mod
>> raise Error, "can't provide both argument and block to
>> Model.dataset_module" if block_given?
>> dataset_extend(mod)
>> mod
>> else
>> @dataset_module ||= dataset_module_class.new(self)
>> @dataset_module.module_eval(&Proc.new) if block_given?
>> dataset_extend(@dataset_module)
>> @dataset_module
>> end
>> end
>>
>>
>> When does the block actually get yielded? I don't think &Proc.new quite
>> does it...
>>
>
> That's where you're wrong. Proc.new without a block takes the block
> passed to the method (yes, even if you don't capture it with &):
>
> a = Sequel::Model(:a)
> a.dataset_module{def foo; 1 end}
> a.foo + a.dataset.foo
> # => 2
>
> In general, one reason to use Proc.new over capturing with & is that you
> can choose whether to do proc activation (turn block into proc) inside of
> the method instead of always doing it. That can have some advantages
> performance-wise in certain cases, though not in this particular case.
>
> Thanks,
> Jeremy
>
--
You received this message because you are subscribed to the Google Groups
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/d/optout.