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
| require 'fileutils' | |
| Dir.mkdir("hello") unless Dir.exist?("hello") | |
| FileUtils.mkdir_p("/tmp/foo/bar/baz/this/is/easy/no") | |
| Dir["/etc/**/*"].each { |f| puts IO.readlines(f).grep(/chad/i) rescue 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
| Welcome to Scala version 2.10.0 (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_51). | |
| Type in expressions to have them evaluated. | |
| Type :help for more information. | |
| scala> import play.api.db.slick.Config.driver.simple._ | |
| import play.api.db.slick.Config.driver.simple._ | |
| scala> new play.core.StaticApplication(new java.io.File("."))[info] play - database [default] connected at jdbc:mysql://localhost/scala_speakers?characterEncoding=UTF8 | |
| [info] play - Application started (Prod) | |
| res0: play.core.StaticApplication = play.core.StaticApplication@4aa65618 |
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 Foo | |
| def self.included(klass) | |
| klass.extend ClassMethods | |
| end | |
| module ClassMethods | |
| def foo(name) | |
| (class << self; self; end).send :attr_accessor, name | |
| end | |
| 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 Class | |
| def attr_with_default(attr_name, default_value) | |
| attr_writer attr_name | |
| define_method(attr_name) do | |
| instance_variable_get("@#{attr_name}") || default_value | |
| end | |
| end | |
| end | |
| class Person |
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
| require 'csv' | |
| module Exporter | |
| DEFAULT_EXPORT_TABLES = [ Invoice, InvoiceItem, Item, Merchant, Transaction, User ] | |
| DESTINATION_FOLDER = "tmp/" | |
| def self.included(klass) | |
| klass.extend ClassLevelMethods | |
| 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 add(key, value, dictionary = Proc.new{}) | |
| lambda do |x| | |
| key == x ? value : dictionary.call(x) | |
| end | |
| end | |
| d = add("a",5) | |
| d = add("b",6, d) | |
| p d.call("b") |
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
| for file in app/**/*rb; do | |
| echo -n $file, " . "; git --no-pager log --pretty="format:%ai" -1 $file; echo; | |
| done |
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 assert_difference(string, expected_difference = 1, &block) | |
| before = eval(string, block.binding) | |
| block.call | |
| after = eval(string, block.binding) | |
| fail "Expected a difference of #{expected_difference}" unless after - before == expected_difference | |
| end | |
| a = 1 | |
| assert_difference("a", 1) do | |
| a += 1 |
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 create_multipler(factor) | |
| ->param{param * factor} | |
| end | |
| times_2 = create_multipler(2) | |
| p times_2.(4) | |
| exit | |
| class Foo | |
| 1_000_000_000.times do |n| | |
| define_method("times_#{n}") do |param| |
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
| Around methods: | |
| method_missing, method_added, singleton_method_added, method_removed, singleton_method_removed, method_undefined, singleton_method_undefined | |
| Around classes and modules | |
| inherited, append_features, included, extend_object, extended, initialize_copy, const_missing | |
| Marshaling | |
| marshal_dump, marshal_load | |
| Numbers | |
| coerce, induced_from |