ruby

How can I get better at/learn more about Ruby?

I have recently started learning Ruby, as my first programming language. I feel comfortable with the syntax, and I've done numerous tutorials that just teach the same basics. I have written a few small programs (including my own method for sorting an array that I thought was pretty smart until someone told me to Google 'Bubble Sort'), bu...

type of object references in ruby

Hello, I am new to Ruby and currently trying a few examples from the Ruby book I am using as a guide: class Account attr_accessor :balance def initialize(balance) @balance = balance end end class Transaction def initialize(account_a, account_b) @account_a = account_a @account_b = account_b end def debit(account,amount) a...

Ruby on Rails Authlogic password not valid

I am trying to implement Authlogic. Registering is fine, it enters all the necessary details into my database.. .. but when I try to log in, it gives me the error: 1 error prohibited this user session from being saved There were problems with the following fields: Password is not valid My password is valid. I am not ...

Web page summary with Ruby

Can anyone recommend a Ruby library for creating a summary of a given URL? What I have in mind is the sort of one- or two-sentence summary as seen in search engine results. ...

How can I duplicate a Ruby core class name and still use that core class in my class?

I am creating a very limited Time class in which I want to make use of the core Time class's parse method. So I end up with something like this... class Time def parse(str) @time = # I want to use Time.parse here end end How can I break out of my newly defined Time class and access the core Time class without renamin...

Share session data between sites?

Hi, i'm working on multisite and I'd like to share session data between two or more sites. I have session id, but what is the best way to retrieve session data from cookie store? Or it will be better to enable ActiveRecord session store and use find_by_session_id method to retrieve session data? Using this way - I need to configure one s...

Cumulative array sum in Ruby

What is the slickest, most Ruby-like way of calculating the cumulative sum of an array? Example: [1,2,3,4].cumulative_sum should return [1,3,6,10] ...

replace id with name in collection_select

In my application i have a collection_select on my members table, the members table only contains id's. It has an user_id, project_id, role_id, and so on. I want show the members name in the collection_select. But i only have the user_id in the members table, how can i show the names from the user table as options? <%= collection_selec...

What is the equivalent of Java CLASSPATH in Ruby ?

I would like to run ruby programs from anywhere. I think I have understood it is RUBYLIB. But I can't make it work. Could you give examples ? Thx JC ...

Rails 2.3 nested attributes issue

I'm running into to a issue with a nested form which I'm sure should be easily solved, yet I can't find a way around it Basically I have the following relationship event has_many :contacts => through :event_contacts the nested form works perfectly as long as I'm creating new contacts each time. If I include a drop down to allow sel...

authlogic shared session

Hi, all. I have shared between 2 sites ActiveRecord Session Store. On the first i've created UserSession object. Is there any way to restore UserSession on the second if i know session_id? ...

Rails: named_scope, lambda and blocks

Hi, I thought the following two were equivalent: named_scope :admin, lambda { |company_id| {:conditions => ['company_id = ?', company_id]} } named_scope :admin, lambda do |company_id| {:conditions => ['company_id = ?', company_id]} end but Ruby is complaining: ArgumentError: tried to create Proc object without a block Any idea...

using authlogic to auto create users bypassing explicit user registeration

Hello, I'm wondering how to go about using Authlogic to auto register a user who chooses to use open id. Right now they have to register first before being able to login in, even if they choose open id, but I'd prefer if they could just login directly provided I get all the necessary details from the open id provider. But I'm not sure ...

Ways to control text-mode console output with ruby

I'm interested in writing a text-mode "gui" application with ruby. This means I need to have a way to output text anywhere I want in the terminal, move cursor around and react directly to different keypresses. Using color would also be a nice plus. Is ncurses the only (or clearly best) way to go, or are there other options to consider? ...

Porting from Ruby 1.8.5 to 1.8.6 | Thread problem

I'm trying to get a sample to work with Ruby 1.8.6. The problem is that the sample was written for Ruby 1.8.5. My assumption is that the problem lies in the way the Thread is called, or not called. This is the sample: class Timer def initialize(resolution) @resolution = resolution @queue = [] Thread.new do while tr...

ruby regular expression begin method a bit confusing

m = /(.)(.)(\d+)(\d)/.match("THX1138.") puts m[0] c = m.captures #=> HX1138 puts c[0] #=> H puts m.begin(0) #=> 1 puts c[1] #=> X puts m.begin(1) #=> 1 puts c[2] #=> 113 puts m.begin(2) #=> 2 I was expecting m.begin(1) to return 2 since X is two elements after the beginning of string. I am reading the book well grounded...

Oracle connectivity in Ruby

In my ruby script, I set to connect to oracle db via: conn = OCI8.new(username, password, database) It works well on my own desktop (Ubuntu), however, when I deploy it onto a lab machine (Ubuntu VM), it has oracle connection error. The machine has all oracle drivers needed because I can connect to it by commandline sqlplus. Also I did e...

Is there anything like Or-Equals from Ruby in .NET/C#?

I'm trying to do something in C# that I do all the time in Ruby, and I wondered what the closest thing would be. If the Enum does not contain a definition for my integer value, I want it to default to a certain value. Can I do this in one line? Ruby-ish assignment (two examples): namedStr = Enum.GetName(typeof(myEnum), enumedInt) || "...

Why does Ruby on Rails use http://0.0.0.0:3000 instead of http://localhost:3000 ?

I am very new to Ruby on Rails so when I tried to follow the official "Getting Started" ruby on rails tutorial, I was a bit disappointed because it went wrong very quickly. Basically it said : …navigate to http://localhost:3000. You should see Rails’ default information page. But when I follow the instructions, I get => Rails 2.3...

Validate multiple selects for preference voting in Rails

I'm trying to create a page where users can select cast their vote for certain items in the order they choose. There are a dynamic amount of options to choose from, e.g. there might be three options to choose from [apples, bananas, oranges], and therefore each option has a select against it, with each select then having three order of p...