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 foo | |
| 2.times do |i| | |
| puts yield | |
| puts "We will go here #{i}" | |
| end | |
| end | |
| foo do | |
| next "Next is the block's return" | |
| "Never returns this" |
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
| IDEA 1 | |
| (1..100).each {|i| puts [i,('foo' if i%3==0),('bar' if i%5==0)].join} | |
| IDEA 2 | |
| (1..100).each {|i| puts "#{i}#{'foo' if i%3==0}#{'bar' if i%5==0}"} | |
| (1..100).each{|i|puts"#{i}#{'foo'if i%3==0}#{'bar'if i%5==0}"} #shortened | |
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 AppConfig | |
| instance_methods.each { |m| undef_method m unless m =~ /^__|is_a\?|empty?/ } | |
| def initialize | |
| @hash = Hash.new do |hash, key| | |
| hash[key] = AppConfig.new unless @finalized | |
| end | |
| end | |
| def method_missing(message, value = 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
| class LRUCache | |
| def initialize(size = 10) | |
| @size = size | |
| @store = {} | |
| @lru = [] | |
| end | |
| def set(key, value = nil) | |
| value = yield if block_given? |
NewerOlder