- Email: apotonick@gmail.com
- Twitter: @apotonick
- Website or Blog: http://nicksda.apotomo.de
- Company: ---
This file contains 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 NotesWidget | |
class Form < MyWidget | |
responds_to_event :create, :with => :create_note | |
preserves_attr :display_mode, :from => '..' | |
def form # The form to add notes | |
@note = Notes.new() | |
render | |
end |
This file contains 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
# in a cell view: | |
%h3 hey, Yahooda | |
render :state => :yay | |
#now, render :state internally does nothing more than | |
elsif opts[:state] |
This file contains 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
# from tag_helper_test.rb | |
# now: | |
# TAG TODO: Move this into a real template | |
def test_content_tag_nested_in_content_tag_in_erb | |
buffer = content_tag("p") { concat content_tag("b", "Hello") } | |
assert_equal '<p><b>Hello</b></p>', buffer | |
end | |
# better: |
This file contains 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
<?xml version="1.0" encoding="UTF-8"?> | |
<scribes version="0.1"> | |
<snippet><entry><trigger id="ruby">select</trigger><description>select element</description><template>select { |${element}| ${element}.${} }${cursor}</template></entry><entry><trigger id="ruby">when</trigger><description>when</description><template>inject(${object}) do |${injection}, ${element}| | |
${} | |
end | |
${cursor}</template></entry><entry><trigger id="ruby">reject</trigger><description>reject element</description><template>reject { |${element}| ${element}.${} }${cursor}</template></entry><entry><trigger id="ruby">:</trigger><description>hash pair</description><template>:${key} => ${"value"}${,}${cursor}</template></entry><entry><trigger id="ruby">ife</trigger><description>if...else</description><template>if ${condition} | |
${statement_1} | |
else | |
${statement_2} | |
end |
This file contains 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
require 'cell/base' | |
class FakeRoutes # should be sinatra's url helper instance | |
def url_for(*) | |
end | |
def named_routes # required due to a fucking stupid line in AbstractController::UrlFor#25 (3.2.3) | |
# super - _routes.named_routes.helper_names | |
Object.new.instance_eval do |
This file contains 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
xml = "<bla>" + | |
10000.times.collect { "<item />" }.join("") + | |
"</bla>" | |
puts( "elapsed time (xpath): " + Benchmark.realtime do | |
Nokogiri::XML(xml).root.search("./item") | |
end.to_s) | |
puts( "elapsed time: " + Benchmark.realtime do | |
Nokogiri::XML(xml).root.children.find_all do |cld| |
This file contains 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
blk = lambda { def a; end } | |
mod = Module.new { instance_exec &blk } # this should add #a to mod. | |
obj = Object.new | |
obj.extend(mod) | |
obj.a #=> undefined method `a' for #<Object:0x970543c> |
This file contains 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
require 'ostruct' | |
require 'benchmark' | |
require 'representable/hash' | |
# --------- extend | |
module SongRepresenter | |
include Representable::Hash |
This file contains 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
# Here's the original problem: | |
module Feature | |
module ClassMethods | |
def feature | |
end | |
end | |
def self.included(includer) | |
includer.extend ClassMethods |
OlderNewer