ruby

Passing hashes instead of method parameters

I see that in Ruby (and dynamically typed languages, in general) a very common practice is to pass a hash, instead of declaring concrete method parameters. For example, instead of declaring a method with parameters and calling it like this: def my_method(width, height, show_border) my_method(400, 50, false) you can do it this way: de...

RCov doesn't work

Hi, I am currently developing a Ruby gem and want to create metrics. I am using 'metric_fu', but RCov seems to leave my specs. Here is my metric_fu configuration: MetricFu::Configuration.run do |config| config.metrics = [:churn, :saikuro, :flog, :flay, :reek, :roodi, :rcov] config.graphs = [:flog, :flay, :reek, :ro...

Making a Ruby server work on port 80

Hi, I'm creating a simple web server in Ruby, which display's the text LOLZ in the browser. I have this now: #!/usr/bin/ruby require 'socket' server = TCPServer.open(2000) loop do client = server.accept client.puts "HTTP/1.1 200 OK\r\n" client.puts "Content-type: text/plain\r\n" client.puts "\r\n" client.puts "LOLZ" client.close end...

Ruby Linguistics gem

I try to convert number to words but I have a problem: >> (91.80).en.numwords => "ninety-one point eight" I want it to be "ninety-one point eighty". I use Linguistics gem. Do you know some solution for it (prefer with Linguistics). ...

Wait for an iframe to open and load with Selenium

Hello. I have an app in which the user clicks a button, triggering an iFrame to open. I'm having real trouble waiting for this frame to open an load before continuing. I can't use: wait_for_page_to_load because the it's not the page that loads, it's the iframe. I can't use: select_frame because the frame hasn't loaded yet so I'...

Testing controller instance variables with Rack::Test and Sinatra

I have a Sinatra app that serves pages as read-only or editable depending on if the user is logged in. The controller sets a variable @can_edit, that is used by the views to hide/show edit links. How can I test @can_edit's value in my tests? I have no idea how to get at the current instance of the controller under Rack::Test. I use cl...

Replacing Broken External Images With Custom Image

I'm looping through an array of URL strings of images hosted at an external site. It looks something like this: def get_image_urls image_url_array.each do |image_url| puts image_tag image_url end end Which will return the URLs of images hosted on the external site. The problem is, some of these images might be broken (404). S...

Move this logic into the find method?

This is working as is, but I'm pretty sure this is sloppy. Any tips on how to get all of this logic more rails-ish? I'm trying to implement will_paginate with this, but first I need a cleaner way of selecting the right records. #shoe table ------------------------------------- size | brand | color | sold -----------------------...

Making generic before_filters a little less ugly?

Hey folks, I have a few before filters which I am using to control access to resources on a resource-by-resource level. The basic idea is as follows: A user can be a user or admin and can have access to specific resources based on an "accesses" table. Resources/methods can be limited in access to admin, owner, particular users, or eve...

ruby list child pids

How can I get pids of all child processes which were started from ruby script? ...

Rendering Partial from outside main/index.rhtml...Ruby on Rails

Ok I have posted a couple of things that had to do with my problem but I think I have it narrowed down. Here is where I am at: I have my index.rhtml page inside of /views/main and the main_controller is set up correctly. I am attempting to make this page a dashboard of sorts so it needs to reference multiple other views to display their...

Collecting additional parameter Ruby on Rails...

I am building a project management app and need some help with how to pass a parameter (I think that is how you say it). Here is what I have going on. I have a table called "proposals" and "proposals" allow you to create multiple concepts per proposal. I have a table called "concepts" and on each "concept" the user can "comment". The w...

What's the right way to implement equality in ruby

For a simple struct-like class: class Tiger attr_accessor :name, :num_stripes end what is the correct way to implement equality correctly, to ensure that ==, ===, eql?, etc work, and so that instances of the class play nicely in sets, hashes, etc. EDIT Also, what's a nice way to implement equality when you want to compare based on...

What version of Ruby to use in Why's (Poignant) Guide to Ruby

I've been following Why's (Poignant) Guide to Ruby for the past few days, and I've noticed some problems with running his examples. I'm at a crossroads now as to whether I've made a few typos that I can't seem to catch, or that my Ruby version is incompatible. I'm running Ruby 1.8.6 (Win32), and I noticed in Chapter 5 in the irb prompt...

Bypassing Ruby 1.9's new "native" threads.

Ruby 1.9 has threads, but they have lots of problems -- the biggest one is that they don't work the same cross platform (priority behaves differently, loop {} inside a thread will eat the whole process in Solaris, but not Linux nor green threads, etc.). However, they made the new native threads class name the same as the old green class...

Mac OS X options for running a Ruby file in the background repeatedly

I wrote a Ruby script that I want to run in the background repeatedly as long as the computer is running. I was planning on using GeekTool to get this .rb file to run in the background, but I'm having issues seen here using GeekTool to run my script. The thing is that I want this script to be a complete surprise (it's a message display...

Is it possible to call from ruby to mono?

I work for a medium sized business integrating a moderate number of systems into one web application written in Ruby on Rails and running on Redhat. One of the functions of the application is to communicate with remote equipment. Some of the equipment I can communicate with directly, some I have to rely on the equipment reporting in to a...

undefined local variable or method 'within' for User:class

Hi there! I am working with a book to teach myself Ruby-on-Rails. Ruby version is 1.2.3 and rubygems V 1.3.5. I start the console by ruby script/console and enter: user = User.new(:screen_name => "example", ?> :email => "exampleATexample.com", ?> :password => "example") but instead of adding the data to the DB, I get the following: ...

how to make my first Ruby effort more idiomatic

It would be helpful to pick up Ruby for my new gig so this morning I wrote the following. It takes a PGN file of chess games I've played and indexes them by first move. I'd appreciate any suggestions as to how to make it more "idiomatic". Since it doesn't take command line arguments (such as for the filename) and isn't object orient...

Programmable transparent forward proxy

I'm looking for a way to script a transparent forward proxy such as the ones that users point their browsers to in proxy settings. I've discovered a distinct tradeoff in forward proxies between scriptability and robustness. For example, their are countless proxies developed in Ruby and Python that allow you to inspect each request resp...