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
| import java.io.BufferedReader; | |
| import java.io.IOException; | |
| import java.io.InputStream; | |
| import java.io.InputStreamReader; | |
| import java.net.MalformedURLException; | |
| import java.net.URL; | |
| public class Lucky13 { | |
| public static double getWinnings(double bet) throws MalformedURLException, IOException { | |
| return (new BufferedReader(new InputStreamReader(((InputStream)(new URL("http://roulette.engineyard.com/").getContent())))).readLine().indexOf("13") != -1) ? 35 * bet : 0; |
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 Array | |
| def recursive_reverse | |
| return self if empty? | |
| [pop, *recursive_reverse] | |
| end | |
| end | |
| puts [1,2,3,4].recursive_reverse.inspect |
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
| @posts.try(:each) do |post| | |
| # something with post | |
| 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 "Foo BAR baz" | |
| when /bar/i | |
| puts "This will occur" | |
| 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 with_scope(*locator) | |
| locator.compact.empty? ? yield : within(*locator) { yield } | |
| 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
| array = [1, 2, 3, 4, 5] | |
| print_procs = [] | |
| array.each do |i| | |
| print_procs.push lambda { puts i } | |
| end | |
| print_procs.each(&:call) | |
| puts |
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 execute | |
| x = 3 | |
| yield | |
| end | |
| x = 1 | |
| execute { puts x } |
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
| x = 1 | |
| block = lambda { puts x } | |
| block.call | |
| x = 3 | |
| block.call |
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
| actions = [] | |
| for i in [1, 2, 3, 4, 5] | |
| actions.push lambda { puts i } | |
| end | |
| actions.each(&:call) |
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
| actions = [] | |
| [1, 2, 3, 4, 5].each do |i| | |
| actions.push lambda { puts i } | |
| end | |
| actions.each(&:call) |
OlderNewer