ruby

Distributing a RubyQt app

I've written a simple ruby application with Ruby Qt. I recently read about distutils in python, and now I'm trying to figure out how to do something similar in ruby. I do not need to distribute on any OS besides linux, but I'm trying to figure out the best way to do that. Should I figure out how to build a .deb? If so how do deal with t...

Tell the end of a .each loop in ruby

If i have a loop such as users.each do |u| #some code end Where users is a hash of multiple users. What's the easiest conditional logic to see if you are on the last user in the users hash and only want to execute specific code for that last user so something like users.each do |u| #code for everyone #conditional code for las...

How can I create an array of ints in Rails 3. Please help!

Hello! I have a very small question. How can I convert these: [172592596,93038592,154137572] To look like these: ['172592596','93038592','154137572'] Thankful for all help! ...

ruby regex split difficulties, close but not quite

I am having quite the difficulty using regex in ruby to split a string along several delimiters these delimiters are: , / & and each of these delimiters can have any amount of white space on either side of the delimiter but each item can contain a valid space. a great example that I've been testing against is the string 1, 2 /3 and...

Ruby: return a copy of array with [key, value] array from hash

In Python there is dict.inspect() method that returns a list of tuples (link). Is there a similar method in ruby to achieve, well, an array of arrays? #input {:a => 1, :b => 2} #result [[:a, 1], [:b, 2]] ...

What does "Anonymous modules have no name to be referenced by" really mean?

I'm upgrading my Rails app to work with Ruby 1.9 and I keep encountering errors like this: Anonymous modules have no name to be referenced by /home/foo/.gem/ruby/1.9.1/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:585:in `to_constant_name' /home/foo/.gem/ruby/1.9.1/gems/activesupport-2.3.8/lib/active_support/dependencies.r...

Autoload path and STI inheritance

I have two models User and Manager. I use STI to inherit Manager from User model. app/models/user.rb class User < ActiveRecord::Base end custom_lib/models/manager.rb class Manager < User end I have added the custom models to load path as follows: config/environment.rb config.autoload_path += File.join(RAILS_ROOT, "custom_lib",...

How do I use YAML in ruby/rails?

I have a list of accounts I want to save as a YAML file and load it into ruby. Something like this: Account1 John Smith jsmith [email protected] Account2 John Doe jdoe [email protected] Then I want to get the email address of the person with the name of "John Doe" (for example). How do I do this? ...

In Ruby / Rails, what if a gem Foo depends on Bar 1.2.2, and cannot be Bar 2.0, but Wala depends on Bar 2.0?

In other words, can't the versions have conflicts and is there a way to solve it? Such as Foo depends on Bar and Foo doesn't support Bar 2.0, but Wala need to have at least Bar 2.0, so can Rubygems or Bundler or any mechanism handle it? ...

Install Ruby 1.9.2 on Ubuntu not using RVM?

Hi, Is it possible to install Ruby 1.9.2 on Ubuntu not using RVM? ...

Is Ruby or other language going to run faster on Parrot?

I just saw that there is a Ruby to Parrot compiler called Cardinal, which can create code to run on Parrot, which is a VM that can run byte-code. How is the performance of Ruby or any language compile to it and run there because for example, Ruby probably doesn't have pre-compiled byte code. Can it be faster running on Parrot? Python ...

Restful communication between local applications is a good idea?

I wonder if it's a good idea letting local applications (in the same server) communicate with each other entirely through Restful API? I know this is not an uncommon thing, cause we already have applications like CouchDB that is using HTTP REST for communication, even with local applications. But I want to take it to a higher level by ...

What kind of variable is ARGV in ruby?

From what I have read ARGV should be a constant since it is all uppercase, but I was able to write a quick program that changed one of the values in ARGV without error. So what type of variable is ARGV? p ARGV ARGV[0] = "Not the orginal" p ARGV ...

Ruby on Rails -- new install on windows 7 but cant run ruby commands, problem with path?

I just installed ruby on rails on my new computer ( I was using instantrails before) and I'm trying to get everything setup. Im running Windows 7. So I followed the instructions from this tutorial. http://blogupstairs.com/ruby-on-rails/installing-ruby-on-rails-on-windows-7/ The problem i'm guessing is step 3 "Add the newly installed ...

Return a JavaScript's confirmbox response to a ruby program.

Hi all, Sorry if it looks stupid question but is it possible to return the response from a JavaScript confirmbox or messagebox to a ruby program as a value? I click on confirmbox's "yes" button, this response is stored in a variable, and then this variable is returned to ruby? ...

HPricot css search: How do I select the parent/ancestor of a particular element using a string selector?

I'm using HPricot's css search to identify a table within a web page. Here's a sample html snippet I'm parsing: <table height=61 width=700> <tbody> <tr> <td><font size=3pt color = 'Blue'><b><A NAME=a1>Some header text</A></b></font></td></tr> ... </tbody></table> There are lots of tables in the page. I want to find the table which co...

Reindenting HTML with Embeded Ruby Code (erb)

I'm wondering if there's an existent solution to the following problem: I have the following code: <div> <div> <div><%= {:something => 'abc', :else => 'abc', :nice => 'ok'} %> </div> </div> </div> As you can see it's unested and hard to read. I was wondering if there's an existent tool preferably in ruby which c...

ruby on rails rake db:migrate error

hi , i'm starting to learn ruby on rails using this guide : getting_started , i created my project and database but when i run rake db:migrate i get this error: @mona-Extensa-5230:~/rubyDev/Sites/blog# rake db:migrate (in /home/mona/rubyDev/Sites/blog) == CreatePosts: migrating =================================================...

Translating Ruby code to Java

Hi all, I have never used ruby but need to translate this code to java. Can anyone help me. This is the code in Ruby. DEFAULT_PRIOR = [2, 2, 2, 2, 2] ## input is a five-element array of integers ## output is a score between 1.0 and 5.0 def score votes, prior=DEFAULT_PRIOR posterior = votes.zip(prior).map { |a, b| a + b } sum = posteri...

Retrieve all posts where the given user has commented, Ruby on Rails

I have users, posts and comments. User can post only one comment to each post. class User < ActiveRecord::Base has_many :posts has_many :comments end class Post < ActiveRecord::Base has_many :comments belongs_to :user end class Comment < ActiveRecord::Base belongs_to :user belongs_to :post end On userpage (http://host/us...