• Post Reply Bookmark Topic Watch Topic
  • New Topic

Ruby newbie asks for feedback - binary search  RSS feed

 
karthik raghunathan
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

This is my first small Ruby program. I'd like to know if this is idiomatic Ruby. After years of Java, this is fun ! What do I do next ?
Let me know what you think - all feedback, suggestions, alternate implementations are welcome !!

 
Junilu Lacar
Sheriff
Posts: 10950
158
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please UseCodeTags when you post code. I have added them for you this time.
 
Greg Charles
Sheriff
Posts: 3014
12
Firefox Browser IntelliJ IDE Java Mac Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry for the late reply! I'm not totally up on Ruby idioms, but I have a couple of suggestions:

a.nil? instead of a == nil
a.empty? instead of a.length == 0
a.blank? to test for either nil or empty
a.first instead of a[0]

I also slightly prefer not, and, or to !, &&, ||. That may just be me though.

The Euler Problems are good for trying out your chops on a new language. Give a few of those a try.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!