Dynamic method call

On 8/3/07, Paul N. [email protected] wrote:

DSL[0]. Your cases should map to RSpec contexts very nicely.
Actually, we already have integration with Watir built into spec/ui
(available from http://rubyforge.org/frs/?group_id=797). Admittedly it
is less mature than rspec as a whole, but I use it all the time to
drive in-browser testing.

Also, we’re in the process of merging rbehave’s story runner into
rspec to make rspec a full-stack bdd framework. It won’t be long
before we’re able to integrate that w/ spec/ui as well, in which case
you’ll be able to write in-browser tests that look like this:

Scenario “anonymous user tries to access private page” do
Given “an anonymous user” { … }
When “go to /private/page” { … }
Then “should redirect to /login” { … }
end

Sadly, that’s a few months off. Happily, that’s JUST a few months off !

Thanks a lot, Paul, I’ll take a look for sure

2007/8/3, Paul N. [email protected]:

Andrea,

Andrea M.

http://www.superandrew.it

A clever person solves a problem.
A wise person avoids it.

Einstein

Yes, probably i started this post not imaging it would be difficult to
imagine a syntax mixed and merged from 2 language, but since most of you
people aren’t speaking english as a first language, i think it would be
easy
to imagine that for a tester(not a developer, but someone who will use
my
‘scripting language’ built wrapping watir facilities) would be nicer and
easier to understand something like

se_presente_testo(“inserimento effettuato”, "registra(‘testUseCase123’,
‘completo’))

than

if presente_testo then blabla

or blabla if presente _testo

That was not he point, which was how to implement a dynamic call to a
method. The grammar stuff probably at beginning was just a subtilety,
but it
slighty began to make me understand some underlying language mechanisms
that i believe are as powerful as easier compared to other language’s
features.

So thanks a lot for the time to discuss about this, i really like this
list
and i find it is truly live and active as a Ruby community should be! :slight_smile:

2007/8/3, [email protected] [email protected]:

David

Andrea M.

http://www.superandrew.it

A clever person solves a problem.
A wise person avoids it.

Einstein

On 8/3/07, Andrea M. [email protected] wrote:

Yes, probably i started this post not imaging it would be difficult to
imagine a syntax mixed and merged from 2 language, but since most of you
people aren’t speaking english as a first language, i think it would be easy
to imagine that for a tester(not a developer, but someone who will use my
‘scripting language’ built wrapping watir facilities) would be nicer and
easier to understand something like

se_presente_testo(“inserimento effettuato”, "registra(‘testUseCase123’,

What still bugs me is that you are using a dynamic call where there is
no need.

It’s entirely possible to write a method that allows you to do something
like:

se_presenete_testo(“inserimento effettuato”) { registra ‘testUseCase123’
}

which would be one less language construct to reinvent.

On 8/2/07, Todd B. [email protected] wrote:

Thanks for the shortcuts - I didn’t know either of these techniques
could be done. In my example, I do other things inside each WHEN
statement to set up the call, but I condensed my example to post.

Thanks! Todd

You could still get the same benefit by setting up a hash of name-value
papers, e.g.,

actions = {
“drill” => :do_the_drill_thang,
“cut” => :slice_and_dice,

}

send(actions[tool]) if tool

An alternative, maybe better, idea would be to define method aliases,
e.g.,

method_alias :drill, :do_the_drill_thang

send(tool) if tool

dean

On 8/4/07, Bas van Gils [email protected] wrote:

end

sendif :if => 1 < 2, :then => [:p, “gagne”], :else => [:puts, “perdu”]

?

Damn, that’s elegant!

I dig it too, though I like better:

sendif 1 < 2, :then => [:p, “gagne”], :else => [:puts, “perdue”]

just because it kills the redundant if.

On Thu, Aug 02, 2007 at 04:48:30AM +0900, dohzya wrote:

sendif :if => 1 < 2, :then => [:p, “gagne”], :else => [:puts, “perdu”]

?

Damn, that’s elegant!

Bas


Bas van Gils [email protected], http://www.van-gils.org
[[[ Thank you for not distributing my E-mail address ]]]

Quod est inferius est sicut quod est superius, et quod est superius est
sicut
quod est inferius, ad perpetranda miracula rei unius.

On Aug 5, 4:47 pm, “Gregory B.” [email protected] wrote:

send args[:then].shift, *args[:then], &bloc

I dig it too, though I like better:

sendif 1 < 2, :then => [:p, “gagne”], :else => [:puts, “perdue”]

just because it kills the redundant if.

To put in my 2 cents, this offends my senses. Whats wrong with:

if 1 < 2
p “gagme”
else
puts “perdue”
end

or even
1 < 2 ? p “gagme” : puts “perdue”

Calling a method with a hash argument just to perform a condition
makes me cringe, performance wise. Plus it just seems so overly
clever.

On 8/5/07, [email protected] [email protected] wrote:

if args[:if]
Damn, that’s elegant!
p “gagme”
else
puts “perdue”
end

or even
1 < 2 ? p “gagme” : puts “perdue”

Calling a method with a hash argument just to perform a condition
makes me cringe, performance wise. Plus it just seems so overly
clever.

Full ack, though if you look through some of the mess we have seen in
this thread, this looks good by comparison. The issue is that the OP
is building a DSL for non-english speakers and needs to have an if
construct that matches the language. So the send_if bit is part of
the implementation details for that.

That having been said, the only benefit of the above is that it lends
nicely to dynamic buildup of calls, but I’d prefer passing around
lambdas, all else considered equal. It just seems like the OP wants
to avoid blocks in general.

Le lundi 06 août 2007 à 08:47 +0900, Gregory B. a écrit :

end
sendif 1 < 2, :then => [:p, “gagne”], :else => [:puts, “perdue”]

just because it kills the redundant if.

in ruby 1.9 :

sendif 1 < 2, then: [:p, “gagne”], else: [:puts, “perdue”]

as elegant as Objective-C !

if I am very evil :

def then &b ; Proc.new &b ; end
def else &b ; Proc.new &b ; end
def sendif test, then, else
test ? then.call : else.call
end
sendif 1 < 2, then {p “gagne”}, else {puts “perdue”}

but it’s too expensive for a simple function…

Le lundi 06 août 2007 à 19:44 +0900, Robert D. a écrit :

def then &b; b.call end
def else &b; b.call end
sendif 1 < 2, then { p “gagnee”}, else { puts “perdu”}
output: “gagneeperdu” (or “perdugagnee”)
result: nil

the 2 arguments are valued BEFORE calling the function…
you can’t do that without macro or lazy-function

On 8/6/07, dohzya [email protected] wrote:

send args[:else].shift, *args[:else], &bloc if args[:else]

but it’s too expensive for a simple function…
let us make it cheaper then

def then &b; b.call end
def else &b; b.call end
sendif 1 < 2, then { p “gagnee”}, else { puts “perdu”}

My wife made me change the output :wink:

Cheers
Robert