# Ruby-Watit

**URL:** <https://www.ruby-forum.com/t/ruby-watit/170017>\
**Category:** Ruby\
**Created:** [June 11, 2009, 11:14am UTC](https://www.ruby-forum.com/t/ruby-watit/170017 "2009-06-11T11:14:57Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![uthpala2002](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/73ab20/32.png) [@uthpala2002](https://www.ruby-forum.com/u/uthpala2002)\
**Post date:** [June 11, 2009, 11:14am UTC](https://www.ruby-forum.com/t/ruby-watit/170017/1 "2009-06-11T11:14:57Z")

</div>

Hi,

I am using Watir to automate our regression test suite.

I have following question.

In watir I canot expand widgets.Could you please explan me the way to  
expand the widgets using watir tool.

Please refer the screen shot for more information.

---

<div class="post-metadata">

**Author:** ![uthpala2002](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/73ab20/32.png) [@uthpala2002](https://www.ruby-forum.com/u/uthpala2002)\
**Post date:** [June 11, 2009, 11:16am UTC](https://www.ruby-forum.com/t/ruby-watit/170017/2 "2009-06-11T11:16:38Z")

</div>

Uthpala Dissanayake wrote:

> Hi,
> 
> I am using Watir to automate our regression test suite.
> 
> I have following question.
> 
> In watir I canot expand widgets.Could you please explan me the way to write scripts to expand the widgets using watir tool.
> 
> Please refer the screen shot for more information.

---

<div class="post-metadata">

**Author:** ![uthpala2002](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/73ab20/32.png) [@uthpala2002](https://www.ruby-forum.com/u/uthpala2002)\
**Post date:** [June 11, 2009, 11:58am UTC](https://www.ruby-forum.com/t/ruby-watit/170017/3 "2009-06-11T11:58:07Z")

</div>

Hi,

In ruby 1.8.7 this does not work (syntax error):

class A

def test=(val, &block)  
end

end

A.new.test = 10 do  
end

I would really like to an associate a block in this way. Is there a way  
round this?

Cheers,  
James

---

<div class="post-metadata">

**Author:** ![uthpala2002](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/73ab20/32.png) [@uthpala2002](https://www.ruby-forum.com/u/uthpala2002)\
**Post date:** [June 11, 2009, 12:28pm UTC](https://www.ruby-forum.com/t/ruby-watit/170017/4 "2009-06-11T12:28:38Z")

</div>

Whoaa… never do it this way, and it seems doesn’t work in 1.9 too  
and I agree with you, that it should works. Ruby’s bug ??

---

<div class="post-metadata">

**Author:** ![uthpala2002](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/73ab20/32.png) [@uthpala2002](https://www.ruby-forum.com/u/uthpala2002)\
**Post date:** [June 11, 2009, 5:48pm UTC](https://www.ruby-forum.com/t/ruby-watit/170017/5 "2009-06-11T17:48:20Z")

</div>

Thanks for checking this. I guess I should raise a bug report.

---

<div class="post-metadata">

**Author:** ![uthpala2002](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/73ab20/32.png) [@uthpala2002](https://www.ruby-forum.com/u/uthpala2002)\
**Post date:** [June 11, 2009, 6:06pm UTC](https://www.ruby-forum.com/t/ruby-watit/170017/6 "2009-06-11T18:06:00Z")

</div>

> > end
> > 
> > A.new.test = 10 do  
> > end
> > 
> > I would really like to an associate a block in this way. Is there a way  
> > round this?

I’m pretty sure this is not a bug. It’s been discussed once or twice  
before on the ruby-talk list.

What are you trying to do with this syntax? Note the potential for  
ambiguity:

A.new.test = [1,2,3].find do |i| i\>1 end

This is currently parsed as

A.new.test = (  
[1,2,3].find do |i| i\>1 end  
)

---

<div class="post-metadata">

**Author:** ![uthpala2002](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/73ab20/32.png) [@uthpala2002](https://www.ruby-forum.com/u/uthpala2002)\
**Post date:** [June 12, 2009, 4:02pm UTC](https://www.ruby-forum.com/t/ruby-watit/170017/7 "2009-06-12T16:02:11Z")

</div>

On Thu, Jun 11, 2009 at 2:55 AM, James  
French[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I would really like to an associate a block in this way. Is there a way round this?

I don’t think so. It isn’t parsed as a normal method call, its parsed  
as a special construct with the = that is converted into a method call  
in a way which doesn’t support picking up a block. I don’t really  
think that using = this way would be a good idea even if you could.

---

<div class="post-metadata">

**Author:** ![uthpala2002](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/73ab20/32.png) [@uthpala2002](https://www.ruby-forum.com/u/uthpala2002)\
**Post date:** [June 12, 2009, 4:19pm UTC](https://www.ruby-forum.com/t/ruby-watit/170017/8 "2009-06-12T16:19:22Z")

</div>

2009/6/12 Christopher D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> On Thu, Jun 11, 2009 at 2:55 AM, James  
> French[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > I would really like to an associate a block in this way. Is there a way round this?
> 
> I don’t think so. It isn’t parsed as a normal method call, its parsed  
> as a special construct with the = that is converted into a method call  
> in a way which doesn’t support picking up a block. I don’t really  
> think that using = this way would be a good idea even if you could.

+1

If I see this

foo.bar = x do  
something  
end

I assume that “foo.bar” becomes the result of evaluating “x do …  
end”. And the Ruby interpreter does so, too. Joel is absolutely  
right about the ambiguity. Note also that this it is not possible to  
somehow make a block work with a “regular” assignment (i.e. a direct  
variable assignment):

bar = x do  
something  
end

Again, x will be called with the block and the result will be assigned  
to bar. It would be a very bad idea IMHO to introduce inconsistencies  
here. Please rather try to find a different solution. Note that you  
can always do

def bar(&b)  
@block = b  
end

And then

foo.bar do  
something  
end

Kind regards

robert
