Don't write them; they'll be inserted automatically.
Replace function () { ... }
with ->
.
# If you wanted to make a constructor that did some extra stuff | |
# on the newly created object before giving it back to you | |
# you might be tempted to write it like you would in Ruby: | |
class Modal | |
@load: -> | |
modal = new this | |
modal.load | |
modal | |
# This is a module that provides two methods, `expose` and `let`, which | |
# allow you to cleanly and clearly define lazily-evaluated, memoized | |
# values that you can use anywhere in your controllers and views. It's | |
# very similar to the decent_exposure[1] gem, but it works more simply | |
# (and doesn't have a default action when you don't pass a block to | |
# #expose, to keep things very very simple). | |
# | |
# You will want to mix this into ApplicationController. | |
# | |
# == Rationale |
require "attr_extras" | |
class SingleOrMultiple | |
rattr_initialize :value | |
def map(&block) | |
result = | |
if multiple_values? | |
value.map(&block) | |
else |
getClientLocation = -> | |
new Promise (resolve, reject) -> | |
success = (position) -> | |
resolve(position.coords) | |
error = (positionError) -> | |
error = new Error("Error fetching client location: " + positionError.message) | |
reject(error) | |
navigator.geolocation.getCurrentPosition(success, error) |
Object.extend(Object, { | |
clone: function(object) { | |
return object.clone ? object.clone() : Object.extend({ }, object); | |
}, | |
toQueryString: function(object) { | |
return object.toQueryString ? object.toQueryString() : $H(object).toQueryString() | |
} | |
}); | |
var PseudoHash = Class.create(Hash, (function() { |
# Various ideas for improving not_a_mock so that we don't have to track methods manually | |
# Note that none of these work, so don't try them | |
class Object | |
def track_all_methods | |
ancestors = self.class.ancestors - [Object, Kernel, ...] # insert all of Ruby Core classes here | |
instance_methods = ancestors.map {|x| x.instance_methods(false) } | |
class_methods = ancestors.map {|x| x.singleton_methods(false) } | |
methods = (instance_methods + class_methods).flatten.map {|x| x.to_sym } | |
track_methods(*methods) |
#!/usr/bin/env ruby | |
# | |
# In Ruby 1.8.6, there's a bug in YAML that is revealed when you | |
# serialize and then deserialize a large YAML::Omap. If you look | |
# at the generated YAML, it looks like every so often, instead | |
# of an object showing up in the YAML file, the object is skipped | |
# and another a reference to another object shows up. This does | |
# not seem to happen with an Array of values, or an Array of Arrays, | |
# or an Array of Hashes, or a Hash. This behavior was fixed in 1.8.7. | |
# |
# Patch Rails so that a plain text mailer view won't be rendered with the layout | |
# Only tested in Rails 2.2 - I'm not sure how this works with 2.3 | |
module ActionMailer | |
class Base | |
def candidate_for_layout?(options) | |
return false if ActionView::Template === options[:file] && options[:file].content_type == "text/plain" | |
!@template.send(:_exempt_from_layout?, default_template_name) | |
end | |
end | |
end |
#!/usr/bin/perl | |
#================================================================================ | |
# powergrep -- improved rgrep with colors and the ability to omit directories | |
#================================================================================ | |
# Created: 6 Sep 2007 | |
# Last modified: 2 Jun 2009 | |
# (c) 2007-2009 Elliot Winkler | |
#================================================================================ | |
# CHANGELOG: | |
# * 2 Jun 2009 - added --mate option to open matched files in TextMate |