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 method_name(*args) | |
| in 1, 2, 'foo', * | |
| # ... | |
| in *, 'bar', * | |
| # ... | |
| in String, String, * | |
| # ... | |
| else | |
| 'default' | |
| 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
| const ROOT = document.getElementById("root"); | |
| const PREFIX = '::'; | |
| const GRAY = '#CCC'; | |
| const KATEX_OPTIONS = { | |
| throwOnError: false | |
| }; | |
| function slicePrefix(str) { | |
| return str.slice(PREFIX.length); | |
| } |
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 DashingRefinement | |
| refine Integer do | |
| def -(b) "#{self}-#{b}" end | |
| end | |
| refine String do | |
| def -(b) Date.parse("#{self}-#{b}") 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
| # 1 + 1 | |
| AstBuilder.build('1 + 1').to_ast.source | |
| => "1 + 1" | |
| # From s-expressions | |
| ast = AstBuilder.build { s(:send, s(:int, 1), :+, s(:int, 1)) }.to_ast | |
| => s(:send, s(:int, 1), :+, s(:int, 1)) | |
| # Current | |
| ast.source |
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
| # Original Code | |
| hash = { something: 'fun' } | |
| method_called(with, some, hash) | |
| # AST | |
| (begin | |
| (lvasgn :hash | |
| (hash | |
| (pair | |
| (sym :something) |
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 :route | |
| (args | |
| (arg :verb) | |
| (arg :path) | |
| (optarg :options | |
| (hash)) | |
| (blockarg :block)) | |
| (begin | |
| (...) | |
| (lvasgn :signature |
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
| # Bad - Hard to read | |
| some.really.long.chain_of_things(:with, | |
| :arguments, | |
| :that, | |
| :are, | |
| :out_here, | |
| :is_unreadable, | |
| :at_a_glance) | |
| # Good - Eye doesn't flow far right then |
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
| names = %w( | |
| @OtherChrisPine @DaveAronson @mellowfish @ktcarrel18 @yvonesre @molbrwn @_MylesHigh_ @DoodlingDev @nilsding @mae701 | |
| ) | |
| totally_random_results = "Lemur fun!" | |
| .chars | |
| .map(&:ord) | |
| .zip(names.shuffle.map(&:ord)) | |
| .sample | |
| .sum |
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
| Cons = Struct.new(:head, :tail) | |
| case Cons[1, Cons[2]] | |
| in Cons[head. tail] then [head, tail] | |
| end | |
| # => [1, #<struct Cons head=2, tail=nil>] | |
| case Cons[1, Cons[2]] | |
| in Cons[1, Cons[head, tail]] then [head, tail] | |
| 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
| case { it: { works: { on: 1, nested: 'hashes' }, cool: true } } | |
| in it: { works: { on: Integer, nested: String }, cool: TrueClass } | |
| true | |
| else | |
| false | |
| end | |
| # => true | |
| case [{ that: { includes: [:this, :too] }}, { more: 'splats'}, {see?: true}] | |
| in [{ that: { includes: Array } }, *] |