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 A | |
| private | |
| def haha | |
| puts "haha" | |
| end | |
| end | |
| A.new.method(:haha).unbind.bind(Class.new(A).new).call | |
| # "haha" |
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
| # 1. alias_method before prepend | |
| module PreA | |
| def foo | |
| puts "pre a" | |
| super | |
| end | |
| end | |
| class A | |
| def self.foo |
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 ModulePrepend | |
| def autoload(*args) | |
| puts args.inspect | |
| super | |
| end | |
| end | |
| class Module | |
| prepend ModulePrepend | |
| 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
| #!/usr/bin/ruby | |
| COLON = ':'.freeze | |
| UNDERSCORE = '_'.freeze | |
| TAB = "\t".freeze | |
| NAMESPACE = 'NAMESPACE_YOU_WANT_MODELING::'.freeze | |
| # Colons are invalid characters in DOT nodes. | |
| # Replace them with underscores. | |
| # http://www.graphviz.org/doc/info/lang.html |
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 MultipleInitializers | |
| def new_using(method, *args) | |
| instance = self.allocate | |
| raise 'implement me' unless instance.respond_to?(method.to_sym, true) | |
| instance.send(method.to_sym, *args) | |
| instance | |
| 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
| class A | |
| def initialize | |
| haha | |
| end | |
| def haha | |
| puts "a" | |
| 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
| class SimpleProxy | |
| instance_methods.each do |m| | |
| unless m.to_s =~ /^(?:nil\?|send|object_id|to_a|tap)$|^__|^respond_to|instance_variable_get/ | |
| undef_method m | |
| end | |
| end | |
| def initialize(object) | |
| @object = object |
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 format_currency(number) | |
| return number if number.blank? | |
| ("%.2f" % number).reverse.gsub(/(\d{3})(?=\d)/, '\\1,').reverse | |
| 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 format_currency(number) | |
| return number if number.blank? | |
| parts = ("%.2f" % number).split('.') | |
| parts[0].gsub!(/(\d)(?=(\d\d\d)+(?!\d))/, "\\1,") | |
| parts.join('.') | |
| 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
| /** | |
| * impress.js | |
| * | |
| * impress.js is a presentation tool based on the power of CSS3 transforms and transitions | |
| * in modern browsers and inspired by the idea behind prezi.com. | |
| * | |
| * | |
| * Copyright 2011-2012 Bartek Szopka (@bartaz) | |
| * | |
| * Released under the MIT and GPL Licenses. |