This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# frozen_string_literal: true | |
Map = Struct.new(:addresses) do | |
def within_radius(kms) | |
within_range = [] | |
addresses.each do |address| | |
within_range << address.to_s if address.kms <= kms | |
end | |
within_range | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# frozen_string_literal: true | |
# observable object aka subject | |
module Observable | |
def attach_observer(observer) | |
@observers ||= [] | |
@observers << observer unless @observers.include?(observer) | |
end | |
def remove_observer(observer) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
within find('tr', text: 'My title') { click_link 'edit' } | |
item = find(".selector", text: "Company") | |
.first(:xpath, ".//..") # parent node | |
.find(".selector2") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
https://thoughtbot.com/upcase/videos/rack | |
require "rack" | |
require "thin" | |
class HelloWorld | |
def call(env) | |
[ 200, { "Content-Type" => "text/plain" }, ["Hello World"] ] | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
http://augustl.com/blog/2008/procs_blocks_and_anonymous_functions/ | |
Procs are useful code organization tools. Let’s say that you want to calculate the running time for a few code snippets, in order to benchmark them. To do this elegantly, you want to be able to call a method and pass some code to it, and have the execution time returned. | |
Here’s how you can use procs to do just that: | |
def time(a_proc) | |
start = Time.now | |
a_proc.call | |
puts Time.now - start |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.