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
# Turn a PEG on its head! Generate some compliments. | |
class Complimenter | |
def compliments | |
phrases | |
end | |
def phrases | |
phrase + ". " + maybe { phrases } | |
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
def missing(message) | |
if message.is_a? Symbol | |
puts "The environment is missing #{message.to_s.upcase}" | |
else | |
puts message | |
end | |
end | |
desc "Check the environment for proper setup" | |
task :checkenv do |
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
class HasDependents | |
def initialize(dependent_class=Kid) | |
@dependent = dependent_class.new | |
@dependent.parent = self | |
end | |
end | |
class Kid | |
attr_writer :parent | |
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
(function(undefined) { | |
// In here, undefined is back to normal, | |
// because we passed the function no params! | |
})(); |
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
ruby-1.9.2-p290 :001 > class Foo | |
ruby-1.9.2-p290 :002?> def bonk | |
ruby-1.9.2-p290 :003?> @bonk = nil | |
ruby-1.9.2-p290 :004?> end | |
ruby-1.9.2-p290 :005?> end | |
=> nil | |
ruby-1.9.2-p290 :006 > f = Foo.new | |
=> #<Foo:0x007ff15c1e65b8> | |
ruby-1.9.2-p290 :007 > f.bonk | |
=> nil |
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
def hunt_for_bugs(score, location) | |
bug_work(hidden_bugs(location), :hide_points).size | |
end | |
def fix_bugs(score, location) | |
just_fixed = bug_work(found_bugs(location), :hit_points) | |
@bug_list.reject! { |bug| bug.dead? } | |
just_fixed.size | |
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
# @paragraphs is an Array of Strings - various puts'es confirm this. | |
@paragraphs.each do |paragraph| | |
renderer = HH::LessonParaRenderer.new(container) | |
markdown = Redcarpet::Markdown.new(renderer) | |
p paragraph # Just checking - it's a String! | |
# raises: <TypeError: wrong argument type Array (expected String)> | |
markdown.render(paragraph) | |
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
module RSlow | |
class HtmlResource < ParsableResource | |
attr_accessor :doc, :scripts, :stylesheets, :images | |
def initialize(url) | |
super | |
@doc = Nokogiri::HTML(@contents) | |
@scripts = fetch_script_resources(".//script", 'src', JsResource) | |
@stylesheets = fetch_stylesheet_resources(".//link[@rel]", 'href', CssResource) | |
@images = fetch_image_resources(".//img", 'src', Resource) |
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
module RSlow | |
class HtmlResource < ParsableResource | |
attr_accessor :doc, :scripts, :stylesheets, :images | |
def initialize(url) | |
super | |
@doc = Nokogiri::HTML(@contents) | |
@scripts = fetch_script_resources(".//script", 'src', JsResource) | |
@stylesheets = fetch_stylesheet_resources(".//link[@rel]", 'href', CssResource) | |
@images = fetch_image_resources(".//img", 'src', Resource) |
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
stop_words_arg = case stop_words_arg | |
when :guess then guess_language(string) | |
when Symbol then stop_words(stop_words_arg) | |
when Java::CueLangStop::StopWords then stop_words_arg | |
when nil then nil # is this one really necessary? it documents, but it seems overkill | |
end |
NewerOlder