You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a property_of block that needs to contain some special logic I have for choosing a state and city. I need to make sure the city selected is within the chosen state. I want to do something like this:
properties = property_of do
state = choose(*states)
city = choose(*cities_within_state(state))
[state, city]
end
This does not work because cities_within_state is a method defined in an included module, which doesn't seem to be available within the context of the property_of block (though it is available outside it). I need to invoke the method within the property_of block because that is the only scope in which the state variable exists.
I was able to come up with a workaround to invoke the the method within the block:
properties = property_of do
state = choose(*states)
cities = Class.new.extend(ModuleContainingMethod).cities_within_state(state)
city = choose(*cities)
[state, city]
end
Is there a better way of doing this?
The text was updated successfully, but these errors were encountered:
I have a
property_of
block that needs to contain some special logic I have for choosing a state and city. I need to make sure the city selected is within the chosen state. I want to do something like this:This does not work because
cities_within_state
is a method defined in an included module, which doesn't seem to be available within the context of theproperty_of
block (though it is available outside it). I need to invoke the method within theproperty_of
block because that is the only scope in which thestate
variable exists.I was able to come up with a workaround to invoke the the method within the block:
Is there a better way of doing this?
The text was updated successfully, but these errors were encountered: