# Using if block\_given? method

**URL:** <https://www.ruby-forum.com/t/using-if-block-given-method/122786>\
**Category:** Ruby\
**Created:** [December 12, 2007, 4:44am UTC](https://www.ruby-forum.com/t/using-if-block-given-method/122786 "2007-12-12T04:44:51Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![martin\_mercy2001](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/d2c977/32.png) [@martin\_mercy2001](https://www.ruby-forum.com/u/martin_mercy2001)\
**Post date:** [December 12, 2007, 4:44am UTC](https://www.ruby-forum.com/t/using-if-block-given-method/122786/1 "2007-12-12T04:44:51Z")

</div>

Hi everybody,

I have created a simple parser. i have used @tag method to store tag  
start and tag end. my requirement is how to read attributes and its  
values when it has more than one attributes like,  
This is the input string,

I need output like

tag start : aaa  
attribute name: size  
attribute value : 100  
attribute name : name  
attribute value : size  
tag end : aaa

i have read character by character and i have executed tag start and tag  
end.  
i have read attribute naes and values also but my program actually not  
displaying it properly like my output is

tag start : aaa  
attribute name : name  
attribute value : size  
tag end : aaa

my program is actually rewritting the old ones. i have used @tag to  
store tag start and tag end and i have called thosed using if  
block\_given? method. i have used parse\_attribute, parse\_attribute\_value  
method to read attribute names and values. How tyo make it work properly  
when multiple atrribute names and values are given.

Thanks in advance

---

<div class="post-metadata">

**Author:** ![martin\_mercy2001](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/d2c977/32.png) [@martin\_mercy2001](https://www.ruby-forum.com/u/martin_mercy2001)\
**Post date:** [December 12, 2007, 4:01pm UTC](https://www.ruby-forum.com/t/using-if-block-given-method/122786/2 "2007-12-12T16:01:05Z")

</div>

dare ruby wrote:

> I have created a simple parser. i have used @tag method to store tag  
> start and tag end. my requirement is how to read attributes and its  
> values when it has more than one attributes like,  
> [snip]

Answer here:  
[http://groups.google.com/group/comp.lang.ruby/browse\_frm/thread/87b5fb008b22b453/22fe3736ee69efbf](http://groups.google.com/group/comp.lang.ruby/browse_frm/thread/87b5fb008b22b453/22fe3736ee69efbf)

I suggest you stop using ruby-forum until it is fixed, and instead use  
another source that lets you see the answers people are providing.

---

<div class="post-metadata">

**Author:** ![martin\_mercy2001](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/d2c977/32.png) [@martin\_mercy2001](https://www.ruby-forum.com/u/martin_mercy2001)\
**Post date:** [December 12, 2007, 7:10pm UTC](https://www.ruby-forum.com/t/using-if-block-given-method/122786/3 "2007-12-12T19:10:18Z")

</div>

On 12.12.2007 04:44, dare ruby wrote:

> displaying it properly like my output is  
> when multiple atrribute names and values are given.  
> I am not really sure what you are asking here but in case you are  
> parsing XML: did you consider using an XML parser, for example REXML in  
> stream mode?

robert

---

<div class="post-metadata">

**Author:** ![martin\_mercy2001](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/d2c977/32.png) [@martin\_mercy2001](https://www.ruby-forum.com/u/martin_mercy2001)\
**Post date:** [December 13, 2007, 9:47am UTC](https://www.ruby-forum.com/t/using-if-block-given-method/122786/4 "2007-12-13T09:47:36Z")

</div>

sorry robert and gavin…

sorry…

lets continue our discussion

Actually robert i was not supposed to use REXML or any other inbuilt  
classes in my task.

Robert K. wrote:

> 2007/12/13, dare ruby [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):
> 
> > sorry Gavin, please if you are not intrested in topic please dont reply.  
> > iam new to ruby so i should do what ever i can do to complete my task.so  
> > iam looking for all the sources to perform well.
> 
> Did you actually _read_ and _understand_ Gavin’s message? His was an  
> attempt at helping you getting better feedback.
> 
> robert

---

<div class="post-metadata">

**Author:** ![martin\_mercy2001](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/d2c977/32.png) [@martin\_mercy2001](https://www.ruby-forum.com/u/martin_mercy2001)\
**Post date:** [December 13, 2007, 4:05am UTC](https://www.ruby-forum.com/t/using-if-block-given-method/122786/5 "2007-12-13T04:05:24Z")

</div>

sorry Gavin, please if you are not intrested in topic please dont reply.  
iam new to ruby so i should do what ever i can do to complete my task.so  
iam looking for all the sources to perform well.

Sorry Gavin.

---

<div class="post-metadata">

**Author:** ![martin\_mercy2001](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/d2c977/32.png) [@martin\_mercy2001](https://www.ruby-forum.com/u/martin_mercy2001)\
**Post date:** [December 13, 2007, 10:11am UTC](https://www.ruby-forum.com/t/using-if-block-given-method/122786/6 "2007-12-13T10:11:04Z")

</div>

2007/12/13, dare ruby [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> sorry robert and gavin…
> 
> sorry…
> 
> lets continue our discussion
> 
> Actually robert i was not supposed to use REXML or any other inbuilt  
> classes in my task.

Then you should show some code you have issues with. With the bits  
you provided nobody can really come up with an answer.

robert

---

<div class="post-metadata">

**Author:** ![martin\_mercy2001](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/d2c977/32.png) [@martin\_mercy2001](https://www.ruby-forum.com/u/martin_mercy2001)\
**Post date:** [December 13, 2007, 9:35am UTC](https://www.ruby-forum.com/t/using-if-block-given-method/122786/7 "2007-12-13T09:35:20Z")

</div>

2007/12/13, dare ruby [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> sorry Gavin, please if you are not intrested in topic please dont reply.  
> iam new to ruby so i should do what ever i can do to complete my task.so  
> iam looking for all the sources to perform well.

Did you actually _read_ and _understand_ Gavin’s message? His was an  
attempt at helping you getting better feedback.

robert
