If I have this class:
class A
attr_accessor :b,:c,:d
end
and this code:
a = A.new
h = {"b"=>10,"c"=>20,"d"=>30}
is it possible to initialize the object directly from the hash, without me needing to go over each pair and call instance_variable_set? Something like:
a = A.new(h)
which should cause each instance variable to be ini...
I'm thinking of writing a CLI Monopoly game in Ruby. This would be the first large project I've done in Ruby. Most of my experience in programming has been with functional programming languages like Clojure and Haskell and such. I understand Object Orientation pretty well, but I have no experience with designing object oriented programs....
I have a list of elements (e.g. numbers) and I want to retrieve a list of all possible pairs. How can I do that using Ruby?
Example:
l1 = [1,2,3,4,5] -> l2 = [[1,2][1,3][1,4][1,5][2,3][2,4][2,5][3,4][3,5][4,5]]
...
I have a form_remote working perfectly for the form currency. The only change I want to make is the do away with submit button for a select box. So they just click the correct currency and it submits the ajax request.
<%= collection_select(:currency, :set, Currency.find(:all, :conditions => 'primary_source = "ECB"'), :code, :pretty_na...
I want to take a value like:
ff0000
and make it into a byte array containing those hex values:
\xff\x00\x00
I'm not clear on how to do this using str.unpack
...
I'm new to Ruby, and I'm trying to query an existing MS Access database for information for a report. I want this information stored in an Excel file. How would I do this?
...
Hello community,
I'm learning to program with Ruby on Rails and I've reached my hardest task yet. I have two tables, each containing a list of business categories (I.E. Thai Food Restaurant, Plumber, Office Supply Store). These two tables come from two different APIs where I'm essentially acting as the middle-man between them. They list...
From The Ruby Way:
This book is largely intended to answer questions of the form of "How do I…?" As such, you can expect to do a lot of skipping around. I'd be honored if everyone read every page from front to back, but I don't expect that. It's more my expectation that you will browse the table of contents in search of techniques you n...
Hi guys. I have a little question about how ruby interprets de ensure clause in the code.
As i know, ensure clause must always be enclosed by begin and end tokens.
For example, if i write this piece of code a kENSURE error will be raised (C:/Documents and Settings/jlomonaco/Desktop/borrar.rb:3: syntax error, unexpecte
d kENSURE, expect...
I have a script that I want to loop indefinitely outside my rails app, essentially it's just writing values over serial (with the SerialPort library), Can I just us backticks to run my script?
Lastly my biggest concern is that the script will block requests to my rails app while its running. I want it to spawn it's own process, is this...
I'm definitely a newbie to ruby (and using 1.9.1), so any help is appreciated. Everything I've learned about Ruby has been from using google. I'm trying to compare two arrays of hashes and due to the sizes, it's taking way to long and flirts with running out of memory. Any help would be appreciated.
I have a Class (ParseCSV) with mul...
I've had problems with autotest before which I resolved by downgrading from ZenTest 4.1.4 to 4.1.3.
$ ruby -v
ruby 1.8.7 (2008-08-11 patchlevel 72) [universal-darwin10.0]
$ rails -v
Rails 2.3.4
Currently I'm finding that on my Mac OS 10.6.1 Snow Leopard system, when I run $ autotest in my project no tests are run and I get this output...
Greetings,
When I try to use Ruby's ri tool in a command prompt window to acquire information about classes, methods, etc. it seems to always fail. For example if I type
ri Array
I get a message saying
Updating class cache with 0 classes... Nothing known about Array
What should I do to configure Ruby's ri tool to work?
Thanks.
...
I've successfully created Ruby-C++ bindings in the past using SWIG where the C++ code was compiled as a dynamic library with the Ruby script connecting to it.
However, I'd like to do it the other way around. Create an executable using C++ and enable it to load and execute Ruby code. Ruby should be able to call functions defined on the C...
I'm fairly new to (J)Ruby - have written a few tiny "demo apps" in RoR
but haven't really gotten right into the syntax though.
I have an app at the moment written in Java that takes an XML file,
parses it and then inserts it into a MySQL database using Hibernate.
What I'd really like to do is see if I can port this to JRuby, -
mainly as...
I'm having troubling completing a task the RESTful way. I have a "tasks" controller, and also a "complete_tasks" controller.
I have this in the complete_tasks_controller create action:
def create
@task = Task.find(params[:id])
@task.completed_at = Time.now
@task.save
end
I tried calling this:
<%=link_to "Complete task", new...
Hi,
I'm trying to use RubyZip to package up some files. At the moment I have a method which happily zips on particular directory and sub-directories.
def zip_directory(zipfile)
Dir["#{@directory_to_zip}/**/**"].reject{|f| reject_file(f)}.each do |file_path|
file_name = file_path.sub(@directory_to_zip+'/','');
zipfile.add(file_nam...
I want to be able to add a record which acts like a symlink. In other words I want to be able to store a record/object which will defer most attributes to another record/object.
The same as on a file system where a symlink points to another file (it own data), yet defers everything else to another file.
class Document < ActiveRecord::...
Assume, i got the following file (input.txt):
name = "Peter"
age = 26
family_status = married
Mentioned lines can be stored in a random order, lie:
family_status = married
name = "Peter"
age = 26
In my program I also have variables family_status, age and name. How do I in a single cycle read those lines from file and assign corresp...
Hi,
what do you prefer for testing JavaScript apps using Cucumber?
I never did it before - I only used Webrat for testing plain html.
I have tried Selenium, but it frustrated me and I didn't find any good documentation about Cucumber in combination with Selenium.
Best regards
...