Don't write them; they'll be inserted automatically.
Replace function () { ... }
with ->
.
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) |
require "attr_extras" | |
class SingleOrMultiple | |
rattr_initialize :value | |
def map(&block) | |
result = | |
if multiple_values? | |
value.map(&block) | |
else |
This gist includes a matcher, have_row
, that makes it possible to assert that a table has a certain row. It also comes with a helper class, Features::Table, that makes it possible to convert a table into an array of arrays or array of hashes, or if you quickly want to find a row based the content of a cell inside it, you can do that too.
# 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 |
# 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 | |
module TableHelpers | |
VALID_FORMATS = [:html, :text] | |
# Find a table on the page and convert it to an array of arrays. | |
# | |
# selector_or_node - A String CSS selector to find the table, or a | |
# Nokogiri::XML::Node object (if you already have a | |
# reference to the table). | |
# options - Optional hash: | |
# columns - An Integer or Range of Integers. Lets you |
module EnumerableMatchers | |
# RSpec already lets you do this: | |
# | |
# arr.should be_any {|item| item["foo"] == 2 } | |
# | |
# However, that's kind of unwieldy to say. So we add this matcher so we | |
# can say one of these alternatives instead: | |
# | |
# arr.should have_any {|item| item["foo"] == 2 } | |
# arr.should have_an {|item| item["foo"] == 2 } |
module HashMatchers | |
def contain(other) | |
Matcher.new(other) | |
end | |
class Matcher | |
def initialize(other) | |
@other = other | |
end |
Instructions: