Regardless of whether it's good practice or not, how can I dynamically call accessor methods in Ruby?
Here's an example class:
class Test_Class
attr_accessor :a, :b
end
I can use the Object.send method to read the variable...
instance.a = "value"
puts( instance.send( "a" ) )
# => value
But I'm having a hard time trying to write ...
I'm making a small ruby command line script and I wanted to know what the simplest way to have the program emit a beep is.
...
In ruby's test/unit, the software indicates how long it takes for the tests to run, and the series of passes, errors and fails act like a pseudo-progress bar.
Apart from using code profiling tools or running tests individually, is there an easy way of telling which test methods are fast and which ones are slow?
...
I would like to do some fairly heavy-duty reflection in the Ruby programming language. I would like to create a function which would return the names of the arguments of various calling functions higher up the call stack (just one higher would be enough but why stop there?). I could use Kernel.caller go to the file and parse the argument...
I feel totally stupid asking this but but I'm new to programming so here goes...
When you run the Ruby ri command from an OS X term window to look at documentation for a particular command, how do you "quit" the documentation? At the end of the document, an (END) is displayed but I don't see how to quit this. I've tried CTRL-C, CTRL-D...
I have a state field that stores the value as 2 characters. For example, Alabama is saved as AL, Alaska is saved as AK, Arizona is saved as AZ, etc. In the show.html.erb, how do I display the long name for the state such as Alabama instead of just showing AL? Is this possible or should I just store the long name in the database such as A...
Similar to this question: http://stackoverflow.com/questions/621340/checkboxes-on-rails
What's the correct way of making radio buttons that are related to a certain question in Ruby on Rails? At the moment I have:
<div class="form_row">
<label for="theme">Theme:</label>
<br><%= radio_button_tag 'theme', 'plain', true %> Plain
...
I'm having ruby instances from mod_rails go "rogue" -- these processes are no longer listed in passenger-status and utilize 100% cpu.
Other than installing god/monit to kill the instance, can anyone give me some advice on how to prevent this? I haven't been able to find anything in the logs that helps.
...
I need to add an element to an existing XML document which uses a namespace that doesn't exist in the original. How do I do this?
Ideally I would like to use REXML for portability, but any common XML library would be okay. An ideal solution would be smart about namespace collisions.
I have an xml document which looks like this:
<xrds:...
Hi,
I'm fairly new to Shoes and ran into two problems.
First I want to set a mask using a partially transparent png, like this:
mask do
image "images/stencilMask.png"
end
Is this possible somehow or can only vector shapes be used?
Apart from that, I noticed a small bug(?) when trying to set a transparent color as a stroke on ...
Does anybody know a place with a bunch of Ruby On Rails Layouts/CSS combinations? I am starting new applications and would like to give them different look, but I am not a designer, so I would love to use someone's else free layouts/css for starters.
...
I'm trying to find info on the p method in Ruby. It seems to produce internal info on the properties of a class but when I try to search for it I get every word that has the letter p in it.
...
def foo
"foo"
end
alias foo2 foo
puts "foo2: " + foo2.object_id.to_s
puts "foo: " + foo.object_id.to_s
In the above example, I expected to see the same object_id output for each method call since they reference the same method. Why do I see different object_id's? When you alias a method in Ruby doesn't the alias refer to the origi...
The is any way to remove the events in Shoes? I searched around many websites and references but I can't found any way to remove a event... I minding that I will need to create my own event manager... its really nescessary? or there is a way to desattach event listeners?
...
I'm working in Rails and I'm looking for a library/gem/plugin to generate a graphic from text. Google Maps doesn't allow you to overlay text, only graphics so I'm looking for a back door to overlay text. Suggestions?
...
I have just started the MIT Introduction to Algorithms course through the material posted online. Along with the course I have also decided to learn/enhance my Ruby skills by coding the algorithms in it.
I am on the first algorithm given, which is Insertion sort, and I have the following code typed up but I am getting this error when I...
I need to do something where the file sizes are crucial. This is producing strange results
filename = "testThis.txt"
total_chars = 0
file = File.new(filename, "r")
file_for_writing = nil
while (line = file.gets)
total_chars += line.length
end
puts "original size #{File.size(filename)}"
puts "Totals #{total_chars}"
like this
origina...
I'm modding a TextMate bundle even though I'm a complete beginner at Ruby. The problem I'm trying to solve is the issue of moving the caret to a certain positition after the command has made its output.
Basically what happens is this:
I hit a key combo which triggers a command to filter through the document and inserts text at the relev...
I'm hoping to use Ruby as a scripting language for my game engine. I've found the usual articles describing how to call Ruby classes from C++ code and vice versa (e.g. here) but I can't quite see how to do what I want with that way of working...
My engine currently uses a little language I wrote myself with Flex and Bison, and a little ...
In order to avoid content duplication, I would like to avoid the pages of my site being accessible by several URLs (with or without trailing slash).
Currently, the URLs
catalog/product/1
and
catalog/product/1/
lead to the same page. My goal is that the second URL redirect to the first (redirection 301, of course). None page of my...