ruby

Rails 3 - translating of routes with I18n

Hello. I want simple thing. Translate routes with I18n like this get I18n.t('routes.login') => "devise/sessions#new", :as => :new_user_session I made file initilizers/locale.rb with I18n.default_locale = :cz It works perfectly when i run 'rake routes', but when i run server it ignore default locale and throw 'translation missing me...

Regex: Possible combine list operator [a-z] with " "{2, } in one expression? Just letters a-z and not more than one whitespace consecutivly

I'm searching for a regular expression that let me replace all chars but letters and digits and one whitespace consecutively. For example: string = "a b c e f g 1 2 3 !" should be replaced in ruby to "a b c e f g 1 2 3 " matching letters and digits is not that problem with [a-zA-Z0-9] with the list operator. but how to combi...

What does super mean here?

I know that if you use super in Ruby it means call the parent's same method. But in some code I see this: def self.post(*args); handle_response super end I wonder what the super means here? ...

How to install Passenger when using RVM?

I'm using RVM and would like to install Phusion Passenger on Snow Leopard. After installing the Passenger gem (version 2.2.15) I try run the Apache module installer script passenger-install-apache2-module. But it compains that it can't find rake: ... * RubyGems... found * Rake... not found * rack... found ... There is alrea...

Method and variable name is the same

If both a method and a variable has the same name it will use the variable. hello = "hello from variable" def hello "hello from method" end puts hello Is it possible somehow to use the method instead without changing name? ...

How can I create new spreadsheet worksheets in Ruby using the Spreadsheet gem?

Specifically what I am trying to do is add new worksheets alongside ones already there. I've tried to use book.create_worksheet :name => 'new_sheet' but it overwrites the previous worksheet. I searched the site here and saw some people using a different gem that allowed "book.add_worksheet" (the Spreadsheet gem is supposed to have suppo...

Sending a hash using eventmachine

I want to send a hash populated with data from a EventMachine client to a server. The problem is that the server receive_date method just prints a string. The server: def receive_data(data) send_data("Ready") puts data[:total] end The client: def receive_data(data) send_data( get_memory() ) end def get_memory sigar ...

Confusing behaviour of Array# bang methods

I was always under impression that bang version of Array methods are only different in the way that they modify object in place. Turns out, some of them like compact!, reject!, flatten!, uniq! also return nil if no changes were made bang bang bang Check out this: ruby-1.8.7-p302 > [1,[2]].flatten! => [1, 2] ruby-1.8.7-p302 > [1,2].fl...

noob confused regarding sequel ORM usage

Hi, I am currently doing small pet project web programming stuff using ruby. I am new to web programming, MVC, ORM and so on, so lots of hurdles here. Anyway, I have difficulties using sequel as ORM. I already have a postgres db running (created without using sequel whatsoever, just used plain postgresql command) but don't know wher...

Ruby: what is the best way to find out method type in method_missing?

At the moment I've got this code: name, type = meth.to_s.match(/^(.+?)([=?]?)$/)[1..-1] But it doesn't seem to be the best solution =\ Any ideas how to make it better? Thanks. ...

Sinatra on Ruby 1.9.2-p0

Hello, I'm quite new to Ruby language (up to now I developed in Groovy + Grails) but since I was curious about it I wanted to try Sinatra on Ruby 1.9.2-p0. I have a trivial website that is contained in /mywebpage and has 2 files: # blog.rb get '/' do 'Hello World!' end get '/impossible' do haml :index end and #config.ru path = ...

Sharing class variables between the instance and the class itself when extended within a module

I'm trying to figure why this code: class BaseClass end module Extensions def self.included(base) base.extend(ClassMethods) end module ClassMethods def message(message) @@message = message end end end BaseClass.send(:include, Extensions) class ExtendedClass < BaseClass message "hello world!" def say_me...

How do you set a has_one default value in ActiveRecord?

I have something like this: class User < ActiveRecord::Base has_one :profile end class Profile < ActiveRecord::Base belongs_to :user end user = User.new user.profile.something #=> ERROR What is a proper way to set a default profile object in this case? I have tried this: class User < ActiveRecord::Base default_scope :include...

Is there a Python equivalent to Ruby symbols?

Is there a Python equivalent to Ruby symbols? If so then what is it? If not then are we stuck with using strings as our keys in dictionaries only? ...

selecting hash values by value property in ruby

In Ruby, I have a hash of objects. Each object has a type and a value. I am trying to design an efficient function that can get the average of the values of all of objects of a certain type within the hash. Here is an example of how this is currently implemented: #the hash is composed of a number of objects of class Robot (example name...

Installing a Ruby version with rvm froze my computer--can I test to see if it installed correctly?

I recently refreshed my Linux installation with Mint 9 (based on Ubuntu 10.04) 64-bit, no Ruby packages at all, and started with a clean install of rvm. But when I ran rvm install 1.9.2, after half an hour or so of some heavy CPU usage the computer froze altogether. I powered down and restarted it, and rvm tells me that ruby-1.9.2-p0 is...

map geo coordinates (lat, lng) to map (x, y)

I have the geo-coordinates (latidute & longitude) of some cities and would like to get the x,y coordinates so can plot them into a map. The map is a standart one, just like http://www.wordtravels.com/images/map/Spain/Fuerteventura_map.jpg for example. I tried several formular I found, but none seems to really work :(. Simple javascrip...

Trying to go to a certain step after its completed one in ruby

Alright. I want it so the following would happen, Heres a sample: puts "what would you like to see?" var = gets.chomp if var == "z" puts "this" elsif var == "d" puts "stack" elsif var == "y" puts "overflow" else puts "I don't understand that." end Currently it works fine up until I want to have the user redefine the 'var'....

typing 'rails console' doesn't start?

I typed this: >rails console and got this: Usage: rails new APP_PATH [options] Options: [--skip-gemfile] # Don't create a Gemfile -d, [--database=DATABASE] # Preconfigure for selected database (options: mysql/oracle/postgresql/sqlite3/frontbase/ibm_db) # Default: sqlite3 .. .. . I'm...

MS Word recognizing Heading/Font etc?

Hi, I want to read a MS word document and Identify Header/Bold font words/Underscored words, etc? is there a way to solve this problem programmatically? I want the suggestion in Java or PHP or Ruby if possible, else if there is some meta-data available also let me know, Thanks Ram ...