Last active
November 22, 2016 19:47
-
-
Save jah2488/8f4e3b968289107e870b to your computer and use it in GitHub Desktop.
Ruby will allow you to do some pretty amazing... errr terrifying things.
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 Foo | |
| def initialize(default = case $glob | |
| when "foo" then (def foobar; "hi!" end) | |
| end) | |
| @default = default | |
| end | |
| end | |
| Foo.new #=> #<Foo:0x007f849f37be98 @default=nil> | |
| $glob = 'foo' | |
| Foo.new #=> #<Foo:0x007f849bbf47e0 @default=:foobar> | |
| Foo.new.methods.first #=> :foobar |
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 Foo | |
| attr_accessor :bar, | |
| :baz, | |
| def initialize(foo) | |
| @foo = foo | |
| end | |
| end | |
| Foo.new('my-bar') #=> ArgumentError: wrong number of arguments (1 for 0) 😕 | |
| Foo.new.methods.take(6) #=> [:foobar, :bar, :bar=, :baz, :baz=, :initialize=] 😰 | |
| f = Foo.new | |
| f.initialize = 'hello' | |
| f.initialize # => 'hello' | |
| #Thanks to Gavin Stark for pointing this one out. |
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
| <section> | |
| <%= render partial: 'posts/form', locals: {:@user => current_user, :@post => post} %> | |
| </section> | |
| <!-- This will re-assign the instance variables @user and @post --> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment