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
I want to create two records which refer to each other, but | |
Bindata seems to not want to let me do that. | |
The two solutions I came up with are to create a copy of one | |
record to another class with most the same functionality, or | |
to create an anonymous struct in one to copy most the functionality. | |
Both of these solutions require me to repeat myself, so I'd | |
like to create a more compact version like the first example. | |
Am I defining things wrong or does Bindata simply not allow |
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 CoolCollection | |
include Enumerable | |
def initialize | |
@elements = [] | |
end | |
def <<(elem) | |
@elements << elem | |
end | |
def each &block |
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
describe Pitch | |
let(:pitch) {Pitch.new} | |
describe "#+" do | |
context "when you add 1 to a pitch" do | |
its "frequency is bigger" do | |
expect((pitch + 1).frequency).to be > pitch.frequency | |
end | |
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 Dog | |
end | |
dog = Dog.new | |
eigen = class << dog | |
self | |
end | |
eigen.superclass | |
#=> Dog |
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 Object | |
def eigen | |
str = caller[0] | |
/\w+(?=')/ =~ str | |
singleton_class.send $&.to_sym | |
end | |
end | |
class Animal | |
def speak |
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
//Java syntax | |
timer.runEverySecond2((int x) -> { | |
System.out.println("Hello, world! Your # is: " + x); | |
}); | |
//Ruby syntax | |
timer.runEverySecond2(->(x) { | |
$stdout.print("Hello, world! Your # is: " + x.to_s); | |
}); |
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 'sound' | |
Sound::Device.new {|d| d.play Sound::Data.new.sine_wave(440, 500, 1)} | |
# This is the short way that opens and closes the device automatically | |
# Here is the more verbose way: | |
device = Sound::Device.new("w") | |
format = Sound::Format.new(Sound::Format::PCM) | |
data = Sound::Data.new(format) |
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 Human | |
attr_reader :children | |
def initialize | |
@children = ["Joe", "Henry"] | |
end | |
end | |
#=> nil | |
human = Human.new | |
#=> #<Human:0x2a19bd8 @children=["Joe", "Henry"]> | |
human.children << "Mary" |
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 GemName | |
module CoolClassInterface | |
module Win32 | |
def func_a; end | |
def func_b; end | |
end | |
module Linux | |
def func_a; end # but now I don't have DRY code. How do I make Win32 and Linux share this? | |
def func_c; 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
threads = [] | |
threads << Thread.new do | |
Thread.stop | |
puts "(first) I started up again!" | |
end | |
threads << Thread.new do | |
Thread.stop | |
puts "(second) I started up again!" |