ruby

Rails: find out if an IP is within a range of IPs

This is a tricky one... How can you tell if an ip, say 62.156.244.13 is within the range of 62.0.0.0 and 62.255.255.255 Is there a simple Ruby way to do this, or how can I solve this? ...

What is best way to execute a Ruby program from a Ruby program?

I would like to do something like this from a Ruby script, within a loop: Write a file a.rb (which changes each iteration) execute system(ruby 'a.rb') a.rb writes a string with results to a file 'results' a.rb finishes and Ruby returns 'true' (assuming no errors) the calling script reads the file 'results' and takes action. I expect ...

Appropriate DSL syntax

Im trying to code my own DSL for file manipulation, just for the sake of learning. My goal is to make it understandable and easy to code. Here are 3 alternatives for appending a string to a database.yml: 1. append("windows").to("database.yml") 2. append(string: "windows").to(file: "database.yml") 3. append_string("windows").to_file(...

Are Dynamic Class Methods possible in Ruby?

Possible Duplicate: How do I use define_method to create class methods? I am trying to do this: class Foo class << self def runtime_method(*methods) methods.each do |name| define_method "self.#{name}" do |*args| "dynamic class method #{name.inspect}" end self.class_eval do ...

How to make 'will_paginate' lazyload in rails 3?

In rails3, almost all query interface change to be lazyloading now, but 'will_paginate' will hit the database imediately after you use the 'paginate' method. How can I make it lazyload records? ...

Nokogiri HTML parsing help

I want to parse an html file using nokogiri ...I am able to do that but i only want text and no cdata ot javascript ...since my js and divs are all over th file ..please offer a gud solution ...

400 bad request from twilio's REST API using twilio-ruby

I'm trying to get started with Twilio's REST API using the rubygem twilio-ruby, and I've hit a snag. Here's my code: h = {:From => "123-123-1234", :To => "123-123-1234", :Body => "hey"} account = Twilio::RestAccount.new(ACCOUNT_SID, ACCOUNT_TOKEN) resp = account.request("/#{API_VERSION}/Accounts/#{ACCOUNT_SID}/SMS/Messages", 'POST', h) ...

Check if module exists in ruby

I'm dynamically defining a module name from an argument passed on the cli, for example "Required::Module::#{ARGV.first}" Is there any way to check if that module exists? Also, how would I run methods on it not knowing it's exact name? ...

ruby gem flickr-fu license problem

I've trying to get the flickr-fu gem to search correctly only for commercial friendly photos but with no luck. It seems to ignore the parameter altogether. photos = flickr.photos.search(:text => "anything", :tags => 'architecture', #:license_id => '4,6,5', ...

Get index of string scan results in ruby

I want to get the index as well as the results of a scan "abab".scan(/a/) I would like to have not only => ["a", "a"] but also the index of those matches [1, 3] any suggestion? ...

Unable to install sqlite3-ruby gem

I've xcode 3.0 installed. And I need to install sqlite3-ruby gem (for rhosync). When I run: sudo gem install -l sqlite3-ruby I get following error: Building native extensions. This could take a while... ERROR: Error installing sqlite3-ruby: ERROR: Failed to build gem native extension. /System/Library/Frameworks/Ruby.framework/V...

How Jammit handle view specific JavaScript

Hi guys, I'm trying to adopt Jammit in my Rails application. Default config provided in documentation grabs all js files including view specific javascript: embed_assets: on javascripts: workspace: - public/javascripts/vendor/jquery.js - public/javascripts/lib/*.js - public/javascripts/views/**/*.js - app/views/work...

Why am I unable to launch a URL via Ruby script?

Dear all, I am a Selenium (Ruby) newbie. I am trying to launch google homepage as below: @selenium = Selenium::SeleniumDriver.new("localhost", 4444, "*firefox", "http://www.google.com", 10000); @selenium.start However, after the script runs, it launches firefox with below URL: http://localhost:4444/selenium-server/core/Blank.html?st...

What is the difference between these two statements, and why would you choose them?

I'm a beginner at rails. And I've come to understand two different ways to return the same result. What is the difference between these two? And what situation would require you to choose one from the other? Example 1: Object.find(:all).select {|c| c.name == "Foobar" }.size Example 2: Object.count(:conditions => ['name = ?', 'Fooba...

help with activemerchant and discount codes

any suggestions on how to use activemerchant with discount codes where cart total can = $0.00 ...

Adding both a collection and a custom field to a Select Box

I am making a select box, and I'm using a collection in it. But at the top of all the selections I want to add something that otherwise wouldn't be in that collection. Here is my select box : = select (@organization, "tabs", @organization.tabs.collect { |t| [t.title, t.id] }, {}, {:class => "text_tab_link"} ) And I would like to ad...

Flatten an array of strings in Ruby

What's the best idiomatic (cleanest) way to convert an array of strings into a string, while keeping the enclosing quotes for each elements. In other words, from this: a = ["file 1.txt", "file 2.txt", "file 3.txt"] I'd need to get this "'file 1.txt' 'file 2.txt' 'file 3.txt'" Single and double quotes could be interchanged here. The...

How do I publish vendor/_____/public/* files?

I have installed a plugin to my Rails app. The plugin has files in its public directory that I want to make available. For example, vendor/plugins/myplugin/public/javascripts/myplugin.js. Can I make this available via Rails at /javascripts/myplugin.js? I've got it working by copying the files from vendor/plugins/__/public/* to public/...

instance_eval vs class_eval in module

class Foo include Module.new { class_eval "def lab; puts 'm' end" } def lab super puts 'c' end end Foo.new.lab #=> m c ======================================================================== class Foo include Module.new { instance_eval "def lab; puts 'm' end" } def lab super puts 'c' ...

How does Ruby (on Windows) find your Requires (libraries)

What technique does a ruby script use to find your libraries / requires on Windows. I have an install of Ruby 1.8.7 on Windows to the path C:\Ruby187 and non of my "requires" work. For example, just a test file require "rack" gives no such file to load -- rack (LoadError) gem list rack is there ...