ruby

Ruby - See if a port is open

I need a quick way to find out if a given port is open with Ruby. I currently am fiddling around with this: require 'socket' def is_port_open?(ip, port) begin TCPSocket.new(ip, port) rescue Errno::ECONNREFUSED return false end return true end It works great if the port is open, but the downside of this is that occasio...

JRuby vs YARV performance ---notable difference?

I've read that the latest version of the Ruby interpreter (YARV) will have substantial performance improvements due to bytecode compilation. My question is has anyone tried running this against JRuby? Any noticable differences in execution on Windows? This link had some good metrics but most were run on Linux...http://antoniocangiano.co...

What's the best resource for learning Rails for a raw beginner?

I want to tell someone what to look at to learn Ruby and Rails. He knows PHP and is a smart guy. For Ruby, I recommended David Black's Ruby for Rails, warning him that the Rails chapters are outdated. What do I recommend for Rails? Perhaps the "beta book" version of AWDR, third edition? I'm wondering whether it's close to being a comp...

Ruby Ecosystem (rake, capistrano, mongrel, etc.?) basics

So I am diving into Ruby (and Rails) and back-end web development in general, and it seems to me there is a huge ecosystem of Ruby projects that seem to be totally essential. I am thinking of projects like Rake, Rack, Mongrel, Gems, Capistrano specifically. Besides these apps' own documentation on their respective project websites, can...

Rails - Flow control question, is there a better way?

I am trying to lock-down a few controllers based on role and the 'posts' controller by whether or not they ANY permissions assigned. This appears to be working, but I'm wondering if there is a clean way to handle this. This is what I have in the application controller, which I'm calling as a before filter... if controller_name == 'users...

Return first match of Ruby regex

I'm looking for a way to perform a regex match on a string in Ruby and have it short-circuit on the first match. The string I'm processing is long and from what it looks like the standard way (match method) would process the whole thing, collect each match, and return a MatchData object containing all matches. match = string.match(/reg...

How can I access a 'Browse...' dialog in Shoes?

Okay so I want to use Shoes for some of my programs, but what I absolutely need is a "Browse..." dialog so the user can browse for a directory/file locally. How can I do that? ...

How do I get the "irb(main):001:0>" prompt instead of ">>"

Hi, Ruby is preinstalled on my Mac and so I wanted to have a look at it. First thing I noticed, is that irb prompts >> instead of irb(main):001:0>. I can't find anything on how to change this with Google because everyone is using irb(main):001:0> in their code ;-) Can you help me out? PS: It's not that I think Ruby is broken, but I wan...

Is ruby strongly or weakly typed ?

Is ruby strongly or weakly typed ? Presumably the same is true for Javascript. ...

Learning Treetop

I'm trying to teach myself Ruby's Treetop grammar generator. I am finding that not only is the documentation woefully sparse for the "best" one out there, but that it doesn't seem to work as intuitively as I'd hoped. On a high level, I'd really love a better tutorial than the on-site docs or the video, if there is one. On a lower leve...

Installing Webby on Ubuntu

I'm trying to install webby on Ubuntu ubuntu-8.10. So far I have installed Ruby 1.8, and RedCloth for Ruby 1.8. When I tried to install webby (using gem) I received the error: Error installing webby: webby requires hpricot (= 0.6.0, runtime) So naturally I tried to install hpricot: sudo gem install hpricot --version=0.6.0 But t...

Installing Compass (Following the Compass Primer)

I am currently following the Compass Primer I've followed all the steps for installation on Ubuntu 8.10, and when I try to run it, to ensure that it's installed correctly, it gives me a big mess of errors: sudo /var/lib/gems/1.8/bin/compass /var/lib/gems/1.8/gems/chriseppstein-compass-0.3.8/lib/compass/commands /install_rails.rb:5:...

Page displays true after running command: 'webby'

So, I'm running though the webby tutorial and I get to the part where you run the webby command for the first time to generate the website in the /output directory. I do that, and next I'm told to open output/index.html. I do so, and the only thing that displays is: true I view the source...and all that is displayed is true Th...

Removing accents/diacritics from string while preserving other special chars (tried mb_chars.normalize and iconv)

Hi, There is a very similar question already. One of the solutions uses code like this one: string.mb_chars.normalize(:kd).gsub(/[^x00-\x7F]/n, '').to_s Which works wonders, until you notice it also removes spaces, dots, dashes, and who knows what else. I'm not really sure how the first code works, but could it be made to strip only...

Passing a method as a parameter in Ruby

I am trying to mess around a little bit with Ruby. Therefor I try to implement the algorithms (given in Python) from the book "Programming Collective Intelligence" Ruby. In chapter 8 the author passes a method a as parameter. This seems to work in Python but not in Ruby. I have here the method def gaussian(dist, sigma=10.0) foo end ...

I Don't Understand How to Express a Relationship Between Three Separate Tables

Given the following tables in ActiveRecord: authors sites articles I don't know how to express that an author is paid a different amount depending on the publication, but that authors working for the same publication have different rates: John publishes an article in Foo for $300 John publishes an article in Bar for $350 John publi...

rails if object.nil? then magic '' in views?

This is one of those things, that maybe so simple I'll never find it because everyone else already knows it. I've got objects I have to check for nil in my views so I don't dereference a nil: <%= if tax_payment.user; tax_payment.user.name; end %> Or I could do this variant: <%= tax_payment.user ? tax_payment.user.name : '' %> So t...

Python/Ruby IDE (Windows)?

Are there any Windows IDEs that support both Ruby and Python? I'm talking about the type of IDE that has syntax suggestions (auto-completion feature). I've tried Netbeans but it only seems to support Ruby (maybe there's a way to add Python support?) ...

How do you run a specific test with test/spec (not a specific file, but a spec within a given file)?

With Test::Unit, I can run: ruby path/to/test.rb --name=test_name_that_i_want_to_run Thus far, I have not been able to figure out how to do this with test/spec specifications. I am wondering if the way that specifications are automatically named does not allow me to do something like this. ...

How do you downgrade rubygems?

I have rubygems 1.3.1 installed but I want to go back to 1.2.0. What's the command to downgrade rubygems? ...