ruby

Fastest way to send data over internet between ruby programs?

Hi, what's the best way to pass data between two ruby programs over the internet? The data is small and needs to be passed frequently. Also, since this happening over the internet, it needs to be secure. I'd appreciate any help, extra points for a pointer to some guides on this topic. ...

Ruby Time Calculations

I am trying to determine the duration of elapsed time minus any interruptions. The method below seems inefficient and silly is there a better method? The user specifies an end_time and a start_time are and records any interruptions as an integer representing minutes. def duration ((end_time - start_time).seconds - interrupt.minutes) ...

Checking for internet connection

How to check for internet connection using Ruby. ...

How to run a single shoulda context test in ruby Test::Unit framework

I can typically test a regular Test::Unit method using the following commandline syntax for a method "delete_user_test": ruby functional/user_controller_test.rb -n delete_user_test Now when I'm using the shoulda plugin with Test::Unit I try to use the same technique as follows: ... context "Deleting a User" do should "remove user ...

Rails functional test file access

I need to access a file in a Rails functional test in test/functional/main_controller_test.rb. If I mention the file within "", and the included file is placed in test/ directory, I can run the test using: $ cd test $ ruby functional/main_controller_test.rb But, I get a cannot find file error, when I use it from the top-level Rails p...

What is the difference between the different Ruby 1.9 builds?

Hello, There are quite a few versions of Ruby 1.9 floating around. There are a few Ruby 1.9 builds for the different operating systems at the official Ruby language site here: http://www.ruby-lang.org/en/downloads/ There are also other 1.9 versions at Ruby Forge: http://rubyforge.org/frs/?group_id=167&release_id=38052 What are the...

Pass additional parameters to a controller

I have this link to create a new page: "new" %> The code called in the controller is this: def new @page = Page.new @visuals = Visual.find(:all) end I would like to pass an additional parameter to pre-set a field in the form, something like this: "new/parent_id/2" %> and in the controller def new @page = Page.new ...

Regexp : how to get every group of MatchData ?

I have the following Regexp : regexp=/(\w+) \s* : \s* (\w+) \s+ (.*) \s* ;?/ix And I am trying to get the captures: names, direction, type = iotext.match(regexp).captures This works fine for a single "x : in integer;" , but how could I also get all the groups of other match data in my file : "x : in integer; y : in logic; z : i...

How to use ActiveRecord in a ruby script outside Rails?

I have a small ruby script in which I'd like to use ActiveRecord to easily access a database model. What is the best way to do it? ...

The <<- operator on Ruby, where is it documented?

Hi, I recently used the <<- operator to output a multi-line string, this way... <<-form <h1>Name to say hi!</h1> <form method="post"> <input type="text" name="name"> <input type="submit" value="send"> </form> form But I stole the <<- operator from some Open Source code, but I didn't find any documentation on it. I kinda...

Calling Lisp from Ruby/Rails?

How might you call a Lisp program from a Rails application?... For example, allow the end user to enter a block of text in the Rails web app, have the text processed by the Lisp program and return results to the Rails app? ...

Ruby Autotest with add_mapping

I am trying to add a hook in Autotest to trigger tests when javascript files are changed. Below the is the .autotest file I am using. The syntax seems to be correct, but nothing is happening when a javascript file is updated. The first hook works fine, the second does not. Autotest.add_hook :initialize do |at| at.add_mapping(%r%^s...

ruby include question

class Foo def initialize(a) puts "Hello #{a}" end end module Bar def initialize(b) puts "#{b} World" end end class Sample < Foo include Bar def initialize(c) super end end Sample.new('qux') #=> qux World Why output is not 'Hello qux' ? credit for code ...

ruby and HTTParty

Hi, I'm requesting an internal API with lots of different interface, each is REST : /users/ /users/username/contacts/ /users/_username/properties/ ..... All this interfaces have a common authentication via a call to /login and return an auth_key that need to be used in every others calls So I made a class for e...

Ruby GIS - Converting NAD83 to WGS84

I'm in the processing of developing a GIS component for our product and I have the need to convert NAD83 to WGS84. Does anyone know of any Ruby libraries that are available that do this? Or experience with anything that might do this? I had previously done this using a library in .Net/C#, but so far I haven't had much luck tracking ...

Why is String#scan not finding all the matches?

Let's use this as sample data : text=<<EOF #if A==20 int b = 20; #else int c = 30; #endif And this code : puts text.scan(/\#.*?\#/m) Why is this only capturing this: #if A==20 int b = 20; # I was expecting this to match as well: #else int c = 30; # What do I have to modify so that it captures that as well?...

Reflecting on the class of the immediate ancestor

Apple < ActiveRecord:Base Orange < ActiveRecord:Base piece_of_fruit = Apple.new I want to know whether piece_of_fruit is an Apple or an Orange - even though both are derived from ActiveRecord:Base. Is there a reflection method that will tell me the next class in the inheritance tree (Apple/Orange). What about if I want to look at ea...

initializing copy of photo in a different model with paperclip plugin for rails

Here's my question. I have a user model with one attached avatar. This model has many personal photos (with accepts_nested_attributes_for). I want to be able to initialize a personal photo automatically after saving a user object with whatever the user avatar turns out to be. So say Bob uploads his avatar, bob will automatically have on...

Ruby on rails session = nil

Hi, In a controller I have 2 actions def action1 session[:test]="test" render :text => session[:test] # output test end def action2 render :text => session[:test] # output nil end I perform first action1 so the session is set Then I perform action2 but session[:test] is nil So what am I doing wrong? ...

help with rails render action vs routing

I was using some image cropping example that I found online and now I got confused. There is actually no "crop" method in my controller. Instead (following the guide) I put a render :action => 'cropping', :layout=> "admin" In my create method. That renders a page the view called cropping.html.erb . It works fine but I have no idea h...