ruby

Ruby on Rails: Converting "SomeWordHere" to "some word here"

I know you can do something like: "SomeWordHere".underscore.gsub("_", " ") to get "some word here". I thought that might be a little too much for something so simple. Is there a more efficient way (maybe a built-in method?) to convert "SomeWordHere" to "some word here"? ...

How to test that invalid arguments raise an ArgumentError exception using RSpec?

I'm writing a RubyGem that can raise an ArgumentError if the arguments supplied to its single method are invalid. How can I write a test for this using RSpec? The example below shows the sort of implementation I have in mind. The bar method expects a single boolean argument (:baz), the type of which is checked to make sure that it actua...

Ruby Regular Expressions - Checking the start middle and end of a line?

Hi, I need to get the "274.20p" out of: <td nowrap="nowrap" class="dataRegularUlOn" style="text-align: right;">274.20p</td> I would like to do regular expressions on: <td class="dataRegularUlOn" > so something like: /<td(.*?)class="dataRegularUlOn"(.*?)>/ I'm using ruby, on linux. thks ...

How do you use the C language to produce a ruby gem?

I would like to see some source code or maybe a link to some that gives at least a stub for writing ruby gems in the C languages (C++?? is that possible too?) Also, some of you may know that Facebook compiles some of their code natively as php extensions for better performance. Is anyone doing this in Rails? If so, what has been your ex...

Ruby ROXML - how to get an array to render its xml?

I'm trying to create a Messages object that inherits Array. The messages will gather a group of Message objects. I'm trying to create an xml output with ROXML that looks like this: <messages> <message> <type></type> <code></code> <body></body> </message> ... </messages> However, I can't figure out h...

Ruby string compare regardless of string case

Hi I need to check for "Apple" = "Apple" TRUE "Apple" = "APPLE" TRUE "Apple" = "Apple1" FALSE in ruby I need a string comparison but for the check to not be case sensitive. thks ...

Why is sqrt() not a method on Numeric?

In Ruby everything is an object. That's why I don't understand why we have the Math module. It seems to me that most (all?) of the functions in the Math module should have been methods on the numeric types like Integer, Float and so on. E.g. instead of Math.sqrt(5) it would make more sense to have 5.sqrt The same goes for sin, co...

Changing RubyGems Install Path

I'm using RVM. I recently updated RubyGems and it seems to have changed my install path. Currently RubyGems looks in /Users/kmurph79/.rvm/gems/ruby-1.9.1-p376 for gems, yet installs them in /Users/kmurph79/.rvm/rubies/ruby-1.9.1-p376/lib/ruby/gems/1.9.1/gems. Currently I have them all symlinked, but I'd like to avoid doing that everyt...

How do you pipe output from a Ruby script to 'head' without getting a broken pipe error

I have a simple Ruby script that looks like this require 'csv' while line = STDIN.gets array = CSV.parse_line(line) puts array[2] end But when I try using this script in a Unix pipeline like this, I get 10 lines of output, followed by an error: ruby lib/myscript.rb < data.csv | head 12080450 12080451 12080517 12081046 12081048 ...

Comparing an array of users to an array of structs with user object as attribute, and returning matches in another array of structs

I have an array of users who are friends. Let us call this array: friends I then have an array of structs. Each struct has a user object as an attribute (it also has a rank attribute). Here's what the struct class looks like, to add some context: class Leader < Struct.new(:rank, :user); end Let us call this array of structs: all_...

RubyOnRails: interface to shell script

Hi, I want to make a button inside my GUI that triggers a shell script. How can I do this? Thanks! ...

Finding out current index in EACH loop (Ruby)

Possible Duplicate: Automatic counter in Ruby for each? I want to find out the current index while i am in the each loop. how do i do so? X=[1,2,3] X.each do |p| puts "current index..." end ...

ldap integeration in ruby

I'm working on integrating ruby with ldap. And it's working fine. Created test.com in ldap and I can bind with it successfully. Then I created a new organizational unit company. Under company there are some users Now I want to bind with the users(authentication) under company organizational unit. I can access the user using Filter.e...

What's the deal with rubygems on Debian? It's different and strange.

I've noticed at least the following oddities around rubygems on Debian (5.0 lenny in my case): Packages go into a different installation location: /var/lib/gems vs /usr/lib/ruby/gems The debian package is rubygems 1.3.6, and updating rubygems to the latest version (1.3.7) doesn't work: $ sudo gem update --system ERROR: While ex...

Performance Impact of Generating 100's of Dynamic Methods in Ruby?

What are the performance issues associated with generating 100's of dynamic methods in Ruby? I've been interested in using the Ruby Preferences Gem and noticed that it generates a bunch of helper methods for each preference you set. For instance: class User < ActiveRecord::Base preference :hot_salsa end ...generates something like...

Ruby encoding problem

I'm just starting to learn Ruby and have a problem with encoding; require 'rubygems' require 'mechanize' agent = Mechanize.new agent.get('myurl.....') agent.page.search('#reciperesult a').each do |item| c = Mechanize.new c.get(item.attributes['href']) puts c.page.search('#ingredients li').text end The output text are shown li...

blacklist test requests from google analytics using watir

Hi, I have to automate tests for a web application which runs google analytics script. I have chosen watir for the automation since I can script all the test cases with the same. The only problem is i dont know how to remove my test requests to the web apps from the google analytics report. Can anyone help me with the same? Is it possi...

How Do I Add Value To All Previous Values In Array

Lets say I have the following array: my_array = [1, 5, 8, 11, -6] I need to iterate over this array and add the values prior to the current value together. An example will probably be easier to understand. I need to return an array that should look something like this: final_array = [1, 6, 14, 25, 19] I have tried doing something ...

Nasty things user supplied ruby code in server can do

I'd like to run user supplied ruby code in server, what are the potentially nasty things that can happen? I mean things like deleting files etc. Can you give me more examples? Thanks in advance! ...

How to send HTML email with styles in rails

I want to know how we can send webpage (HTML page) as an email. I want to add style in a html page like Images or some table formatting. I want to know that should I add style in my "conta.text.html.erb" or I can add CSS in it? ...