Suppose you do this in Ruby:
ar = [1, 2]
x, y = ar
Then, x == 1 and y == 2. Is there a method I can define in my own classes that will produce the same effect? e.g.
rb = AllYourCode.new
x, y = rb
So far, all I've been able to do with an assignment like this is to make x == rb and y = nil. Python has a feature like this:
>>> class ...
I've gotten used to blocks in Ruby and would like to use them in Java. Groovy seems to offer a similar feature but I don't know enough about Groovy to understand whether there are any significant differences in syntax and functionality.
Is a Ruby block equivalent to a Groovy block?
...
I am currently in the process of learning Ruby on Rails. I have been following the Learning Rails podcast and screencasts.
I've run into a problem, well more of an annoyance. Every time the screencast has me kill the mongrel server I am forced to close the console window because CTRL+C isnt killing it as it should. I then have to open ...
I'm learning Ruby in my spare time, and I have a question about language constructs for constants. Does Ruby have an equivalent of the C++ const keyword to keep variables from being modified? Here's some example code:
first_line = f.gets().chomp()
column_count = first_line.split( %r{\s+} ).size()
print column_count, "\n"
I'd like to...
I have a BackgrounDRb worker set up to run its 'sync' method every 15 minutes. Then, say, I want to run the method once just now. I was trying to wrap that in a rake task as follows:
namespace :mytasks do
task :sync do |t|
worker = MiddleMan.worker(:my_worker)
worker.async_sync
end
end
But this doesn't work. It bails out w...
Can you elaborate on the current state of "blocks" (in the Ruby sense) in Python?
What are the language constructs that exist in python? How do they compare to other languages (like Ruby, Smalltalk, [insert more])? Or does python lack of such constructs?
I have so far understood the lambda thing; it is only one-line, but maybe it comes...
I'm currently looking at a hefty Rails test suite. It's nothing I can get into specifics about, but the run time for the entire suite (unit/functional/some integration) can run upward of 5 minutes.
We're completely reliant on fixtures and are we're not mocking and stubbing as much as we should be.
Our next few sprints are going to be ...
Which one to use for process monitoring and why?
...
I have developed a simple library in Ruby and need to use this in several Rails applications (some of which are not built yet). What is the best way to easily add this Ruby library to several Rails applications as and when required? Our team is running Ubuntu and our repository is Mercurial.
Should I use a...
Rails plugin? This would ...
It's an implementation of Sieve of Eratosthenes.
class PrimeGenerator
def self.get_primes_between( x, y)
sieve_array = Array.new(y) {|index|
(index == 0 ? 0 : index+1)
}
position_when_we_can_stop_checking = Math.sqrt(y).to_i
(2..position_when_we_can_stop_checking).each{|factor|
sieve_array[(factor).. (y-1)...
Does anybody know any Ruby on Rails time_select plugins that have only one select box? So the select box has entries like "9:00 AM", "9:15 AM", etc.?
I have seen a few plugins, but nothing like this.
Thanks!
...
Hey all, hope you guys can help; I've followed about every tutorial on the net with no luck.
I've just moved over to Ubuntu 8.10 as my dev box; it's my first serious foray into Linux as a daily-use OS, and I'm having a hard time getting Rails going. I have followed a number of tutorials which all seem to work fine, but when I try and u...
I'm having a problem coming up with a query that would work for these models. I have three models that are connected.
An Organization has many Users, and Users have many StatusEntries
Basically this means I could do
Organization.find(1).users.find(1).status_entries
And have a list of status_entries returned to me.
The problem is I ...
I am wondering if there are any sort of tools that you guys use to kick-start a codeigniter project?
Something similar to how ROR does?
...
I've got the following models:
In plan.rb
has_many :tickets
and in ticket.rb
belongs_to :plan
validates_presence_of :plan_id
When executing the following code in the controller
@plan.tickets.build( ... )
@plan.save
save fails with error_message for ticket: plan can't be blank. (plan is valid.)
...
Note This originally started as a question about 404 errors, but now it's a question why the patch that I applied would make a difference.
How do you get a cached action to return a 404 on all requests that raise an ActiveRecord::RecordNotFound exception, not just the first request?
For example, if you start an empty rails project, add...
I know eql? is used by Hashes to see if an object matches a key*, and you do
def ==(rb)
if you want to support the == operator, but there must be a good reason that Hashes don't use == instead. Why is that? When are you going to have definitions for == and eql? that are not equivalent (e.g. one is an alias to the other) ?
Similarly, ...
Hello!
I have created a Ruby XMPP Framework called babylon. I have then created a few applications with it and even though they run pretty smoothly, it seems that they're eating my computer memory bit by bit.
I suspected leaks, so first, I added this at some point in my code :
puts `ps -o rss= -p #{Process.pid}`.to_i
As suspected, t...
I'm working on an application that reaches out to a web service. I'd like to develop a proxy class that returns a fake response from the service, so I don't have to constantly be hitting it with requests while I'm developing/testing other parts of the app.
My application is expecting a response generated via Net::HTTP.
response = Net::...
Hi there,
I'm having a problem with redirect_to :back. Yes, it's referrers.
I often get the exception (ActionController::RedirectBackError) "No HTTP_REFERER was set in the request to this action, so redirect_to :back could not be called successfully. If this is a test, make sure to specify request.env[\"HTTP_REFERER\"]."
I realise tha...