ruby

Tough to debug. Variables work in irb but the method fails.

I discovered a bug that without a trailing number [0-9], my method will fail. Therefore I used a quick gsub to insert that number. I'm working with this method: def initialize(speciate) y = speciate.gsub(/$/, '1') x = y.scan(/[A-za-z]*\d+/) @chem_species = x.map { |chem| chem.scan(/[A-Z][^A-Z]*/) }.flatten end Whe...

Ruby - problems with user input to integer array

I am trying to accept input of two integers, separated by a space: 3 5 and save that into an integer array. I do this 3 times, but I am having trouble converting this from string to integers. Here is my loop: for i in 1..3 puts "What is point " + i.to_s + " ?" # asks for input s.push gets.split(" ") end Then, I want to have...

How can I force require a file in the console? The 'reload!' command just dosen't work!

I use rails-3.0.0.beta3 and ruby-1.9.2-preview3. I have defined some new methods in the application_controller.rb, and need to test them in the console. If I changed some codes in the application_controller.rb. I have to restart the console. I have tried to use 'reload!' command, just dosen't work. And then I use "require 'applicati...

list of ruby operators that can be overloaded

Is there a list anywhere of all ruby operators that can be overloaded? (Not the ones that can't) ...

How to modify loop variable in ruby?

for i in (0..5) if(i==0) i=4 end puts i end In the above program I excepted the output as - 4 5 But instead it is - 4 1 2 3 4 5 So I conclude that loop variable isnt changing. How can change it? Can anyone tell me? Actually, In my program I need to save the current state of loop and retrive later so that on the next start...

How to capture the text wthin the brackets: (), using regex maybe?

any way would be fine. Perl, python, ruby... ...

Can I access a variable within a heredoc in Ruby?

If I have a method def some_method p = {} string = <<-MY_TERMINATOR Example text blah blah lorem ipsum something or another MY_TERMINATOR end how can I access the variable p[:name] from within the heredoc? ...

How to delete a file in ruby which is still being used?

I am using spreadsheet gem to generate excel file. Now the problem with it is that when we modify an existing file it wont allow to save it with same name http://spreadsheet.rubyforge.org/GUIDE_txt.html and in the running script I cant delete and recreate the file beacause it is still being used. Doing so throws permission denied error. ...

How to update Ruby in Google SketchUp?

Currently Google SketchUp for Mac has Ruby version 1.8.5 which I find a bit outdated. I can update Ruby to 1.8.7 (OSX's version) by the following commands $ cd /Applications/Google\ SketchUp\ 7/SketchUp.app/Contents/Frameworks/Ruby.framework/Versions/Current $ ls Headers/ Resources/ Ruby $ ls Headers/ config.h defines.h inter...

How to know whether a model is new or not?

class Post < ActiveRecord::Base end post = Post.new How do I judge whether the 'post' is a new model which is not pulled from the database? ...

factory_girl + rspec doesn't seem to roll back changes after each example

Similar to the problem described here: http://rpheath.com/posts/411-how-to-use-factory-girl-with-rspec in Short (shorten'd code): spec_helper: config.use_transactional_fixtures = true config.use_instantiated_fixtures = false factories.rb: Factory.define :state do f.name "NY" end in my spec before(:each) do @static_model = ...

Authlogic performance? - Any request with SELECT *

Hi @ all I have a little performance issue with Authlogic - I dealed with them over days... and i can't figure out! The Problem is: I use the standard-Authlogic installation with following code in the application_controler to get the current_user (and to persits the session): def current_user_session return @current_user_session if ...

how to read image file in ruby

how to read image file in ruby suppose i open a jpg file like this path="c:/image/aj.jpg" File.open(path) do end now how do i see this image file ...

ruby fast reading from std

What is the fastest way to read from STDIN a number of 1000000 characters (integers), and split it into an array of one character integers (not strings) ? 123456 > [1,2,3,4,5,6] ...

JSON or XML or serialized array to save in MySQL database

Web app. Get data from services in json & xml formats. And from internal module in hash. Decided to choose one format for all stored data. details : More read than write. Data low nested (< 10). Char count between 1000 - 100000. Programming language - ruby. Framework rails. DB mysql. What's your recommendation? ...

clojure vs. Ruby

I'm ASP.NET developer. I want to learn web development technologies and other languages than Microsofts. I heard about two languages but I don't know which one is better or how to favor one over the other especially that clojure is new somehow. Could anyone help me about why to choose one of them over the other?. Thanks. ...

Application level filtering/data manipulation

I have a model with many different children (has_many). My app needs to lots of different manipulation on the who set of data. Therefore getting the data from the database is pretty simple, so I won't really need to use scopes and finders, BUT I want to do things on the data that are equivalent to say: named_scope :red, :conditions =>...

How to unassign a value?

I have a table similar to the following id | name | address both name and address are not nullable(this i achieve through attribute setters only and not by default) When i create a new record without any default values what will be stored in the table? If the value is null -> if i store a value (say name="MyName", address="Th...

Custom Formtastic Control with Multiple Parameters

I'm attempting to build a custom control for Formtastic that takes a latitude and a longitude, however, I'm not sure how to go about passing the method names through. Ideally I'd have the following in the semantic_form_for block: f.input :latitude, :longitude, :as => :location I've also tried passing with an array: f.input [:latitude...

In rspec, why can't I use be_false etc in helper classes?

When using a helper class with an rspec test, I can't see to use the .should be_false idiom. It's okay in a function defined in a helper .rb file, but when it's within a class the be_false symbol is not found. Example below -- why doesn't this work? How can I use be_false et al in a helper? It seems possible that it's intentional tha...