Is there a way to flatten a hash into a string, with optional delimiters between keys and values, and key/value pairs?
For example, print {:a => :b, :c => :d}.flatten('=','&') should print a=b&c=d
I wrote some code to do this, but I was wondering if there was a neater way:
class Hash
def flatten(keyvaldelimiter, entrydelimiter)
...
I'm trying to write a class that supports nested around filters without introducing an Aspect-oriented library.
class Foo
attr_accessor :around_filter
def initialize
#filters which wrap the following one are the ones with interesting logic
#vanilla do-nothing filter
@around_filter = lambda { yield } # or lambda {|&blk| ...
I have a rake task loaddata.rake.
require File.join(File.dirname(__FILE__), 'load_test_data.rb')
namespace :test do
desc "Insert test data into the database"
task(:loadtest => :environment) do
puts "environment = #{RAILS_ENV}"
puts "load_test_data "; load_test_data
puts "DONE!"
end
end
I have another fi...
For about a year I have been thinking about writing a program that writes programs. This would primarily be a playful exercise that might teach me some new concepts. My inspiration came from negentropy and the ability for order to emerge from chaos and new chaos to arise out of order in infinite succession.
To be more specific, the ...
Hi there,
The following is beginning to become a huge problem for us.
We have about 15 Rails applications for our enterprise, running on a massive server. The problem occurs when two or three applications are wildly popular and they start taking up all the instances in the PassengerMaxPoolSize. As soon as that happens, other applicatio...
Many job sites have broken searches that don't let you narrow down jobs by experience level. Even when they do, it's usually wrong. This requires you to wade through hundreds of postings that you can't apply for before finding a relevant one, quite tedious. Since I'd rather focus on writing cover letters etc., I want to write a program t...
How would I achieve something like below so that when I set the s variable within the block, it also sets the @subject instance variable in my Topic class?
class Topic
def subject(&blk)
blk.call(@subject) if block_given?
@subject unless block_given?
end
end
my_topic = Topic.new
p my_topic.subject #=> nil
my_topic.subject ...
Can someone explain me this Ruby on Rails puzzle?
class Post < ActiveRecord::Base
has_many :comments
end
Post.first.comments.class
=> Array
Array === Post.first.comments
=> false
Array === [ 1 ]
=> true
...
while i am running rake jobs:work.
I am getting this error.
** Invoke jobs:work (first_time)
** Invoke merb_env (first_time)
** Execute merb_env
** Invoke environment (first_time)
** Execute environment
rake aborted!
uninitialized constant Delayed
C:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:443...
My controller data_files_controller.rb
def upload_balances
DataFile.load_balances(params)
end
My model data_file.rb
def self.load_balances(params)
# Pull the file out of the http request, write it to file system
name = params['Filename']
directory = "public/uploads"
errors_table_name = "snapshot_errors"
upload_file = File.join(...
Any idea why hpricot might segfault on this page?
trial_url = 'http://www.controlled-trials.com/ISRCTN56071145/'
doc = Hpricot(open(trial_url))
produces:
/Users/ap257/.gem/ruby/1.8/gems/hpricot-0.8.2/lib/hpricot/parse.rb:33: [BUG] Segmentation fault
ruby 1.8.7 (2009-06-08 patchlevel 173) [universal-darwin10.0]
Abort trap
Please cou...
I installed ruby through the windows installer yesterday.
All seemed fine.
Today, I went installing the rmagick win32 gem like so:
c:\ruby187\bin\gem install rmagick-2.7.1-x86-mswin32.gem
in the directory with the gem.
That also seemed to work fine, got the familiar
1 gem installed
Installing ...[all the ri and other docs].
But after...
I have a Team class that inherits from a Group class. Both Team and Groups have memberships through the same association. However, I need to run a method after a Team memberships is added but not a Group. I currently have something like this:
class Group < ActiveRecord::Base
has_many :memberships,
:class_name => 'Connec...
I'm working a Rails 3 controller that has a very specific, limited purpose, and all I need is for it to respond_to :json.
This screencast says my controller can inherit from ActionController::Metal, and then just include the functionality I need to make things faster:
http://rubyonrails.org/screencasts/rails3/action-controller
When my...
I'm new to Ruby - what tricks can I use to help me find documentation on a object I'm working with? Normally I just do a_var.class or a_var.methods and try to guess what I need or search the web for documentation. Are there other methods or modules that might help?
...
I often want to take out a subpart from an Enumerable. The subpart is sometimes at the beginning and sometimes the end of the original Enumerable instance, and the length used to specify the subpart is sometimes that of the subpart and sometimes its complement. That gives four possibilities, but I only know how to do three of them. Is th...
I'm trying to understand Rails from the ground up. I want to learn how to manually create basic show-all/show-single/CRUD functionality in the framework.
I currently am working on the display-all functionality, but am stopped by an error when I try to request all items in the Products db
Here are the steps I've taken so far:
script/g...
I been intersted in ruby and rails lately but what I always encounter in blog/ podcast / book is they will always teach how to use ruby or rails plugin/ ruby instead of writing one. Did we really always need to use plugin, even thing like authorization? Authenticate? Is it really waste time Or hard to write from start? Then if it hard an...
Given a very simple ruby script:
child = fork do
system 'sleep 10000'
end
5.times do
sleep 1
puts "send kill to #{child}"
Process.kill("QUIT", child)
end
QUIT signal is just lost. Where does it go? Something with default handler which just ignores it?
How to send signal to all processes created by that fork? Is it possible t...
I have ruby on rails installed on my Desktop
running
ruby 1.8.7
and
rails 2.3.8
i want to know is installing Ruby 1.9.1 version will mess up with my Rails apps?
Thx.
...