m.method.method.method not as expected

1 view
Skip to first unread message

jason

unread,
Oct 4, 2009, 8:32:04 AM10/4/09
to Ruleby
dear groupies,

Situation:
=======

rule :for_an_ExistingAction_that_is_in_a_page_further_away_from_the_entry_point,
[ExistingAction, :a, m.existing_action.page.depth >
m.new_action.page.depth] do |v|
puts "EXISTING ACTION FOUND"
end

Complication:
===========

The engine blows up with "nil.depth"

Solution:
=======
however, when I add:
@existing_action_page_depth = existing_action.page.depth
@new_action_page_depth = new_action.page.depth
to my ExistingAction class and change the rule as follows:

rule :for_an_ExistingAction_that_is_in_a_page_further_away_from_the_entry_point,
[ExistingAction, :a, m.existing_action_page_depth >
m.new_action_page_depth] do |v|
puts "EXISTING ACTION FOUND"
end

then the rule matches as expected.

Question
========

is this the correct behavior, a bug, a feature or my mistake?

thanks a million for letting me know.

jason.


Joe Kutner

unread,
Oct 4, 2009, 2:54:43 PM10/4/09
to rul...@googlegroups.com
That is the correct behavior - you can't chain methods in the rule.
But as with your other question, it would be an easy feature to add.

An alternative that would allow you to do the method chaining without
modifying the fact's class would be something like:

rule [ExistingAction, :a, m.existing_action(&c{|existing_action|
existing_action.page.depth > x})] do |v|
puts "EXISTING ACTION FOUND"
end

jason

unread,
Oct 4, 2009, 5:09:35 PM10/4/09
to Ruleby
Thanks for your feedback Joe,

Hmmm, I thought I had tried the method chaining in the conditional
block?? Ahh I remember I needed to pass the entire object to the block
for something like this:

m(&c{|model| model.foo > model.bar})

and that did not work (invalid shorthand) - but yes i would have
expected a straight yield on the block.



On Oct 4, 8:54 pm, Joe Kutner <jpkut...@gmail.com> wrote:
> That is the correct behavior - you can't chain methods in the rule.
> But as with your other question, it would be an easy feature to add.
>
> An alternative that would allow you to do the method chaining without
> modifying the fact's class would be something like:
>
>   rule [ExistingAction, :a, m.existing_action(&c{|existing_action|
> existing_action.page.depth > x})] do |v|
>       puts "EXISTING ACTION FOUND"
>   end
>
Reply all
Reply to author
Forward
0 new messages