# How do I strip off the extra double quote or white space in

**URL:** <https://www.ruby-forum.com/t/how-do-i-strip-off-the-extra-double-quote-or-white-space-in/66162>\
**Category:** Ruby\
**Created:** [August 23, 2006, 6:27pm UTC](https://www.ruby-forum.com/t/how-do-i-strip-off-the-extra-double-quote-or-white-space-in/66162 "2006-08-23T18:27:58Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ban\_Hoang](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/9fc348/32.png) [@Ban\_Hoang](https://www.ruby-forum.com/u/Ban_Hoang)\
**Post date:** [August 23, 2006, 6:27pm UTC](https://www.ruby-forum.com/t/how-do-i-strip-off-the-extra-double-quote-or-white-space-in/66162/1 "2006-08-23T18:27:58Z")

</div>

Hi,

I try to read in an external file to array and compare them to the drop  
down list in our application. I got into the problem when comparing, the  
extra double quotes make the assertion result failed. Can anyone help me  
to make it work?

Thanks for your help,

ps . I posted this question on Nabble but it is pending without reason  
so I try to post it here hope it can go to the list users…

* * *

Below is the code:

* * *

arr = IO.readlines(“dropList.csv”) # read entire contents of the file  
into a single array. Each index of the array is one line.

assert\_equal([arr[0]], $ie.frame(“top”).select\_list(:name,  
“site\_id”).getAllContents)

* * *

This is the csv external file dropList.csv contain:

## :: Select Site :: !!Eastgate\_Mall

1. Failure:

test\_\_02\_DropDown\_list\_verified(TC\_pulldownBoxVerified)  
[DropVerified\_test.rb:45]:

\<[":: Select Site ::,!!Eastgate\_Mall,\n"]\> expected but was

\<[":: Select Site ::", “!!Eastgate\_Mall”]\>.

---

<div class="post-metadata">

**Author:** ![Ban\_Hoang](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/9fc348/32.png) [@Ban\_Hoang](https://www.ruby-forum.com/u/Ban_Hoang)\
**Post date:** [August 23, 2006, 6:36pm UTC](https://www.ruby-forum.com/t/how-do-i-strip-off-the-extra-double-quote-or-white-space-in/66162/2 "2006-08-23T18:36:00Z")

</div>

Hi  
I am a newbie to this mailing list.

I have a couple of queries:

1. Can methods be part of an array definition, which can bear similarity  
to ‘C’ definitions  
of “array of function pointers”, as part of a state machine  
implementation.

2. How can we make C routine call a “method” defined in a ruby script as  
we do it the other way while extending ruby call C routines

Regards,  
Saumya.

---

<div class="post-metadata">

**Author:** ![Ban\_Hoang](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/9fc348/32.png) [@Ban\_Hoang](https://www.ruby-forum.com/u/Ban_Hoang)\
**Post date:** [August 23, 2006, 6:46pm UTC](https://www.ruby-forum.com/t/how-do-i-strip-off-the-extra-double-quote-or-white-space-in/66162/3 "2006-08-23T18:46:02Z")

</div>

On 8/23/06, Dikshit Saumya-G19445 [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Hi  
> I am a newbie to this mailing list.
> 
> I have a couple of queries:
> 
> 1. Can methods be part of an array definition, which can bear similarity  
> to ‘C’ definitions  
> of “array of function pointers”, as part of a state machine  
> implementation.

Look up Object#method and Method in the docs:

you can do [‘aaa’.method(:size), 10.method(“+”)]

UnboundMethod could be useful as well.

Other than that, its possible to call methods by name. I you just need  
to call methods on one object, it is enough to store just their names  
(preferably as symbols):

methods = [:size, :length, :whatever]

then you would for example do: methods.each {|m| ‘aaaa’.send(m) }

---

<div class="post-metadata">

**Author:** ![Ban\_Hoang](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/9fc348/32.png) [@Ban\_Hoang](https://www.ruby-forum.com/u/Ban_Hoang)\
**Post date:** [August 23, 2006, 6:52pm UTC](https://www.ruby-forum.com/t/how-do-i-strip-off-the-extra-double-quote-or-white-space-in/66162/4 "2006-08-23T18:52:03Z")

</div>

On Thu, Aug 24, 2006, Ban Hoang wrote:

> I try to read in an external file to array and compare them to the drop  
> down list in our application. I got into the problem when comparing, the  
> extra double quotes make the assertion result failed. Can anyone help me  
> to make it work?

A couple of options:

1. If your external file is truly CSV (comma-separated values) use a CSV  
parser to parse it. Though, from your example, it doesn’t seem to be  
the case… here’s some code anyway.

…  
require ‘csv’

rows = []

CSV.open(‘dropList.csv’, ‘r’) do |row|  
rows \<\< row  
end  
…

Then compare the parsed rows against your dropdown array.

1. Write your own assertion:

…  
def assert\_equal\_without\_quotes(a,b)  
assert\_equal a.gsub(/[’"]/, ‘’), b.gsub(/[’"]/, ‘’)  
end  
…

Untested, but that might work 😉

Ben

---

<div class="post-metadata">

**Author:** ![Ban\_Hoang](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/9fc348/32.png) [@Ban\_Hoang](https://www.ruby-forum.com/u/Ban_Hoang)\
**Post date:** [August 24, 2006, 8:53am UTC](https://www.ruby-forum.com/t/how-do-i-strip-off-the-extra-double-quote-or-white-space-in/66162/5 "2006-08-24T08:53:23Z")

</div>

Thanks  
Making it a proc really helped.

I have few more problems

How can we make C routine call a “method” defined in a ruby script ?  
I am familiar with extending ruby to call C routines with/without swig.  
But I was not able to find a easy solution for it. The only way it may  
workout is  
spawning the script in a different process/thread from C code and then  
make it do all query/answer sequence by calling a C routine. Is there a  
easy way out?  
Can’t we make a C routine call a specific method in a Ruby Script.

Can we access a C stack from Ruby or vice versa while debugging the  
Ruby extension.

Regards,  
Saumya.

---

<div class="post-metadata">

**Author:** ![Ban\_Hoang](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/9fc348/32.png) [@Ban\_Hoang](https://www.ruby-forum.com/u/Ban_Hoang)\
**Post date:** [August 23, 2006, 7:12pm UTC](https://www.ruby-forum.com/t/how-do-i-strip-off-the-extra-double-quote-or-white-space-in/66162/6 "2006-08-23T19:12:07Z")

</div>

On 8/23/06, Jan S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Look up Object#method and Method in the docs:
> 
> then you would for example do: methods.each {|m| ‘aaaa’.send(m) }

Another approach would be to use Procs in the array instead of  
methods, this would allow you to store arguments in the array entries  
as well, and to execute more than just a method.

actions = [  
lambda {obj.size},  
lambda {obj.length},  
lambda {obj.foo(3, “abc”) }  
lambda {puts “Hi Mom!”; obj.callhome }  
]

then to invoke an action it’s just

actions[n].call

as a variation on this, if the blocks have parameters, you can use  
call(arg1, [arg2,…]) to pass parameters.

–  
Rick DeNatale

My blog on Ruby  
[http://talklikeaduck.denhaven2.com/](http://talklikeaduck.denhaven2.com/)

---

<div class="post-metadata">

**Author:** ![Ban\_Hoang](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/9fc348/32.png) [@Ban\_Hoang](https://www.ruby-forum.com/u/Ban_Hoang)\
**Post date:** [August 25, 2006, 6:56am UTC](https://www.ruby-forum.com/t/how-do-i-strip-off-the-extra-double-quote-or-white-space-in/66162/7 "2006-08-25T06:56:01Z")

</div>

I have few more queries

How can we make C routine call a “method” defined in a ruby script ?  
I am familiar with extending ruby to call C routines with/without swig.  
But I was not able to find a easy solution for it. The only way it may  
workout is spawning the script in a different process/thread from C code  
and then make it do all query/answer sequence by calling a C routine. Is  
there a easy way out?  
Can’t we make a C routine call a specific method in a Ruby Script.

Can we access a C stack from Ruby or vice versa while debugging the  
Ruby extension.

Regards,  
Saumya.

---

<div class="post-metadata">

**Author:** ![Ban\_Hoang](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/9fc348/32.png) [@Ban\_Hoang](https://www.ruby-forum.com/u/Ban_Hoang)\
**Post date:** [August 24, 2006, 1:13pm UTC](https://www.ruby-forum.com/t/how-do-i-strip-off-the-extra-double-quote-or-white-space-in/66162/8 "2006-08-24T13:13:47Z")

</div>

I have few more problems

How can we make C routine call a “method” defined in a ruby script ?  
I am familiar with extending ruby to call C routines with/without swig.  
But I was not able to find a easy solution for it. The only way it may  
workout is spawning the script in a different process/thread from C code  
and then make it do all query/answer sequence by calling a C routine. Is  
there a easy way out?  
Can’t we make a C routine call a specific method in a Ruby Script.

Can we access a C stack from Ruby or vice versa while debugging the  
Ruby extension.

Regards,  
Saumya.
