Skip to content

Instantly share code, notes, and snippets.

@stevenbristol
stevenbristol / self1.rb
Created August 3, 2012 12:58
what is self?
module Logger
def log str
p str
end
end
class Thing
extend Logger
def test_log
@stevenbristol
stevenbristol / Thing3.rb
Created August 2, 2012 12:24
Using extend and include
module Logger
def log str
p str
end
end
class Thing3
@stevenbristol
stevenbristol / thing2.rb
Created August 2, 2012 12:18
Using extend
module Logger
def log str
p str
end
end
class Thing2
extend Logger
log "this does work from class" # => "this does work from class"
@stevenbristol
stevenbristol / thing1.rb
Created August 2, 2012 12:13
Using include
module Logger
def log str
p str
end
end
class Thing1
include Logger
begin
@stevenbristol
stevenbristol / instance_eval and class_eval 2.rb
Created August 1, 2012 12:52
instance_eval and class_eval 2
"string2".instance_eval { p self } # => "string2"
begin
"string2".class_eval { p self }
rescue Exception => e
p e # => #<NoMethodError: undefined method `class_eval' for "string2":String>
end
@stevenbristol
stevenbristol / gist:3226460
Created August 1, 2012 12:38
instance_eval and class_eval 1
String.instance_eval do
def from_instance_eval
self
end
end
String.class_eval do
def from_class_eval
self
end
@stevenbristol
stevenbristol / gist:3188943
Created July 27, 2012 16:16
overriding DecoratedEnumerableProxy
class InvoicesController < ApplicationController
def index
respond_with id InvoicesDecorator.new(invoices, InvoiceDecorator)
end
end
class InvoicesDecorator < Draper::DecoratedEnumerableProxy
def method_regardless_of_invoices_empty_or_not
"yay"
$.rails.showConfirmDialog = (link) ->
okButton =
type: 'btn btn-primary'
text: 'Ok'
click: (noty) -> $.rails.confirmed(link); noty.close()
cancelButton =
type: 'btn btn-danger'
text: 'Cancel'
click: (noty) -> noty.close()
noty
$.rails.showConfirmDialog = (link) ->
html = """
<div id="dialog-confirm" title="Are you sure you want to delete?">
<p>These item will be permanently deleted and cannot be recovered. Are you sure?</p>
</div>
"""
$(html).dialog
resizable: false
modal: true
buttons:
$.rails.showConfirmDialog = (link) ->
message = link.attr 'data-confirm'
html = """
<div class="modal" id="confirmationDialog">
<div class="modal-header">
<a class="close" data-dismiss="modal">×</a>
<h3>#{message}</h3>
</div>
<div class="modal-body">
<p>Are you sure you want to delete?</p>