A to_map
function is very useful when you want to convert models to PLAIN OLD DATA. Think presenters, conductors, APIs, JSON, etc...
Add this monkey-patch to your Rails project and call it on your model instances.
Ruby objects can be built in a way such that they are easier to use/test/debug from the point of view that if you do not automatically run their intended functionality from the constructor, potential side-effects and bugs can be better examined.
In general, I find it helpful to consider a constructors' purpose constrained only to setting instance-level attributes based on the passed arguments or using pre-defined defaults. Anything outside of that, I would consider setting up a class-level factory method.
Consider creating semantically-named factory style class methods that create an object and then call a specific method.
I find this especially helpful for hand-rolled presenters and worker classes (e.g. for Resque).
# Make a backup first! | |
# Place at the root of the desired git repo | |
# Run w/ commit SHA as first argument e.g. ruby fix.rb 57415b9c864e4128dca805b4a8ad7b7e59281ac6 | |
# | |
# All files in your list will be forever removed from the filesystem and git repo from given | |
# commit up to HEAD | |
files = %w( | |
you.r | |
list.of |
Last revised on 03-12-2012
Antiqua, Ltd. operates the Antiqua.IO service, which we hope you use. If you use it, please use it responsibly. If you don't, we'll have to terminate your account.
For paid accounts, you'll be charged on a monthly basis. You can cancel anytime, but there are no refunds.
Last revised on 03-12-2012
Antiqua, Ltd. will collect certain non-personally identify information about you as you use our sites. We may use this data to better understand our users. We can also publish this data, but the data will be about a large group of users, not individuals.
The only personal information required to use the service is your email. This will never be sold, disclosed, or otherwise transferred without explicit advance notification (a minimum of 30 days) and the ability to opt out. The only likely scenario where this would be the case is an acquisition of Antiqua, Ltd..
// QUESTION | |
// write a javascript class, called 'Foo', with a class method 'bar' and an | |
// instance method 'bar' | |
var Foo = function Foo(){ | |
console.log('new Foo instance'); | |
}; | |
Foo.bar = function(){ | |
console.log('Foo::bar'); |
#!/usr/bin/env zsh | |
rvm-shell "ruby-1.9.3-p0" -c "foreman run bundle exec rake "$argv |
require( './boot' ); | |
var DbItem = require( './db_item' ) | |
, item = new DbItem( '123456abcdefg' ); | |
item.queue( function( error , response ){ | |
console.log( 'Response: ' + response ); | |
process.exit(); | |
} ); |
source :rubygems | |
gem "sinatra" | |
group :development do | |
gem "foreman" | |
end |