ruby

In Ruby, must instance variables (of a class) be first defined in "initialize" before it will work?

class Shape def initialize() @blah = "" end end OR...will this work? class Shape @blah = "" def initialize() end end Also, by default, are the instance variables public or private? How do you set them as public or private? ...

What does this line mean in Ruby?

def show render :text => params.inspect end What is render :text =>? What is render, :text, and the =>? Are they standard ruby? ...

What is the Ruby equivalent of this string formatting?

From Python... s = "hello, %s. Where is %s?" % ("John","Mary") How do you do that in Ruby? ...

SOAP services using savon is not working

I have installed savon gem in windows 7 with ruby 1.8. It shows in gem list But when I give require 'rubygems' require 'savon' It gives following error NameError: uninitialized constant Savon from ./savon.rb:3 from C:/Ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require' from C:...

How to convert apache log time to activerecord :datetime

I'd like to save apache logs to MySQL via ActiveRecord. In the apache log, the default time string is like: [13/Aug/2008:00:50:49 -0700] How can I convert it to a ActiveRecord :datetime type? Thanks! ...

Good library/platform for a real-time/parallel HTTP crawler?

I am building a crawler that fetches information in parallel from a number of websites in real-time in response to a request for this information from a client. I need to request specific pages from 10-20 websites, parse their contents for specific snippets of information and return this information to the client as fast as possible. I w...

Is there a tool for assisting with ruby/rails internationalization?

I'm looking for something that will help me to internationalize an existing rails application using I18n. Ideally it would locate string constants (with parameters) and allow me to extract those into a .yml or .rb file replacing the original string with the appropriate t(...) call. Also, or alternatively, a macro to do the same on select...

How to open a file at the same folder of the ruby script?

The following .rb script runs fine if excuting at the script's folder: db = YAML::load(File.open('db.yml')) ActiveRecord::Base.establish_connection(db) The File.open will fail if the script is running outside the script folder. How can I supply the script's path to db.yml? Thanks! ...

SCP with Ruby and a private key

Hi all I have a small problem here: I try to upload a file using SCP and Ruby to a server using a private key. The code looks like: def transfer_file(source_file, destination_file) $log.info("ScpDP: Key=#{@key}") Net::SCP.start(@host, @userName, :keys => @key ) do |scp| scp.upload!(source_file,@folder + destination_f...

How do you determine the nested classes of a class?

In Ruby, how do you determine the nested classes of a class? ...

Good practices for Integration Tests for my rails app external endpoints?

I'll keep it short, I've got a rails app which communicate with other apps, some using SOAP (non-rails apps of course...) and others with REST. I'm making integration tests to ensure that my endpoint wrapper classes have correct mappings and setup. However, they are executed by default by rake test which makes it slow and fragile. I wish...

Accessing Microsoft Exchange server from Ruby

I need to sync MS Exchange's contacts with my Ruby on Rails application. Which is the best way? Would you recommend any existing gems for it? ...

Ruby on Rails: How do you make link_to_unless_current work with parameters?

I'm trying to do something like so: link_to_unless_current "Inbox", messages_path(:inbox => true) But, it seems that link_to_unless_current only works if I go to "http://localhost/messages" and not "http://localhost/messages?inbox=true" (i.e. it doesn't give a link for the latter which is correct, but it does for the former which is i...

Boolean Query / Expression to a Concrete syntax tree

I'm creating a search form that allows boolean expressions, like: "foo AND bar" or "foo AND NOT bar". Is there a library for PHP, Ruby or Java that can transform boolean expressions to a concrete syntax tree? (I could write my own lexer/parser, but I rather use something tried and tested) EDIT: To clarify, I'm not parsing arrhythmic...

Scientific plot with Ruby + wxWidgets

I need to incorporate some scientific plot function into a program written in Ruby with wxWidgets. What's my best solution? I know that 1) PLPlot has a widget for wxWigets, but I'm not aware of any ruby bindings. 2) Python works well PLPlot and wxWigets, but I rather not rewrite the whole thing in python again. Any suggestion would be...

Ruby design and nested classes

I am using Sinatra and I am in the middle of designing some models. My dilemma is that the model is a File and the best name really is just File. I also need a FileStreamer class related to this specific file, which name is also in use. What is the best approach for this design? Can I namespace these classes by nesting them in the same...

wrong # of arguments(0 for 1)

Hello all, Here is my Test model code: require 'rubygems' require 'composite_primary_keys' class VamTest < ActiveRecord::Base set_table_name 'tests' set_primary_keys :service, :host end This is the stacktrace I get when I run the following: >> VamTest.all VamTest.all ArgumentError: wrong # of arguments(0 for 1) from C:/jruby...

How to remove rvm (ruby version manager) from my system?

Hello guys. How can I remove rvm (ruby version manager) from my system? ...

What does this mean ? >> ActionController::InvalidAuthenticityToken

I was curious what that meant in general. But here is the specifics.. I'm doing a sortable jquery project, that touches this rails action : def update_order params[:media].each_with_index do |id, index| media = @organization.media.find(id) media.do_not_touch = true media.update_attribute('position', index+1) end if par...

Is it possible to pass more than one block to a method in Ruby?

Something like: def foo(&b1, &b2) b1.call b2.call end foo() { puts "one" } { puts "two" } ...