# Is there "equalsIgnoreCase" in ruby?

**URL:** <https://www.ruby-forum.com/t/is-there-equalsignorecase-in-ruby/94910>\
**Category:** Ruby\
**Created:** [May 17, 2006, 5:40pm UTC](https://www.ruby-forum.com/t/is-there-equalsignorecase-in-ruby/94910 "2006-05-17T17:40:16Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![viswesh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/5f8ce5/32.png) [@viswesh](https://www.ruby-forum.com/u/viswesh)\
**Post date:** [May 17, 2006, 5:40pm UTC](https://www.ruby-forum.com/t/is-there-equalsignorecase-in-ruby/94910/1 "2006-05-17T17:40:16Z")

</div>

Hi

Please let me know whether any method similar to (“equalsIgnoreCase” in  
java)  
exists in ruby as well…

thanx

---

<div class="post-metadata">

**Author:** ![viswesh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/5f8ce5/32.png) [@viswesh](https://www.ruby-forum.com/u/viswesh)\
**Post date:** [May 17, 2006, 5:56pm UTC](https://www.ruby-forum.com/t/is-there-equalsignorecase-in-ruby/94910/2 "2006-05-17T17:56:54Z")

</div>

On 5/17/06, viswesh [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Please let me know whether any method similar to (“equalsIgnoreCase” in  
> java)  
> exists in ruby as well…

What does equalsIgnoreCase do, and could you not have spent five  
minutes to Google?

-austin

---

<div class="post-metadata">

**Author:** ![viswesh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/5f8ce5/32.png) [@viswesh](https://www.ruby-forum.com/u/viswesh)\
**Post date:** [May 17, 2006, 5:57pm UTC](https://www.ruby-forum.com/t/is-there-equalsignorecase-in-ruby/94910/3 "2006-05-17T17:57:09Z")

</div>

On 5/17/06, viswesh [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Please let me know whether any method similar to (“equalsIgnoreCase” in  
> java)  
> exists in ruby as well…

Yes, it’s called String#casecmp().

---

<div class="post-metadata">

**Author:** ![viswesh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/5f8ce5/32.png) [@viswesh](https://www.ruby-forum.com/u/viswesh)\
**Post date:** [May 17, 2006, 6:46pm UTC](https://www.ruby-forum.com/t/is-there-equalsignorecase-in-ruby/94910/4 "2006-05-17T18:46:09Z")

</div>

Hi Johnson,

can u please correct the code…

puts " what is your name"  
name = gets.chomp

puts " hello “+ name+” how are you"  
fine = gets.chomp

if fine == “good”.casecmp(“goo”)  
#fine == “fine” or  
#fine == “ok” or  
#fine == “wonderfull”  
puts " great"  
else  
puts “oh iam sorry”  
end

thanx

Lyle J. wrote:

> On 5/17/06, viswesh [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > Please let me know whether any method similar to (“equalsIgnoreCase” in  
> > java)  
> > exists in ruby as well…
> 
> Yes, it’s called String#casecmp().

---

<div class="post-metadata">

**Author:** ![viswesh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/5f8ce5/32.png) [@viswesh](https://www.ruby-forum.com/u/viswesh)\
**Post date:** [May 17, 2006, 6:59pm UTC](https://www.ruby-forum.com/t/is-there-equalsignorecase-in-ruby/94910/5 "2006-05-17T18:59:59Z")

</div>

On 5/17/06, viswesh [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> if fine == “good”.casecmp(“goo”)  
> #fine == “fine” or  
> #fine == “ok” or  
> #fine == “wonderfull”

I think that maybe you mean to write:

```
if fine.casecmp("good")
  puts "Great!"
else
  puts "Oh, I'm sorry."
end

```

Hope this helps,

Lyle

---

<div class="post-metadata">

**Author:** ![viswesh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/5f8ce5/32.png) [@viswesh](https://www.ruby-forum.com/u/viswesh)\
**Post date:** [May 17, 2006, 7:03pm UTC](https://www.ruby-forum.com/t/is-there-equalsignorecase-in-ruby/94910/6 "2006-05-17T19:03:37Z")

</div>

On 5/17/06, viswesh [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> if fine == “good”.casecmp(“goo”)

See “ri String#casecmp”.

---

<div class="post-metadata">

**Author:** ![viswesh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/5f8ce5/32.png) [@viswesh](https://www.ruby-forum.com/u/viswesh)\
**Post date:** [May 17, 2006, 7:03pm UTC](https://www.ruby-forum.com/t/is-there-equalsignorecase-in-ruby/94910/7 "2006-05-17T19:03:29Z")

</div>

> can u please correct the code…

you forgot to tell us what you want the program to do, what it’s  
doing instead, the things you’ve already tried to remedy the problem  
and what you think might be the problem.  
-tim
