This file contains 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 Parser | |
def initialize(text) | |
@tokens = text.scan(/\(|\)|[\w\.\*]+/) | |
end | |
def next_token | |
@tokens.shift | |
end |
This file contains 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 VirtualAccountProxy | |
def initialize(&block) | |
@block = block | |
end | |
def deposit(amount) | |
return subject.deposit(amount) | |
end |
This file contains 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 Report | |
attr_accessor :title, :text, :formatter | |
def initialize(&formatter) | |
@title = "No Title" | |
@text = "Not Found" | |
@formatter = formatter | |
end |
This file contains 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 Account | |
attr_accessor :name, :balance | |
def initialize(name, balance) | |
@name = name | |
@balance = balance | |
end | |
def <=>(other) |
This file contains 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 SimpleWriter | |
def write(text) | |
puts text | |
end | |
end | |
module TimeStampingWriter |
This file contains 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
package sandbox; | |
/** | |
* 与えられた数値を 2 倍にして返す関数です。 | |
* | |
* @author monzou | |
*/ | |
public enum DoubleFunction implements Function<Number, Number>, Predicate<Number> { | |
/** Integer 型を倍にする関数 */ |
This file contains 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
package sandbox.wait; | |
import java.util.concurrent.BrokenBarrierException; | |
import java.util.concurrent.ConcurrentMap; | |
import java.util.concurrent.CyclicBarrier; | |
import java.util.concurrent.ExecutionException; | |
import java.util.concurrent.ExecutorService; | |
import java.util.concurrent.Executors; | |
import java.util.concurrent.Future; |
This file contains 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
/** | |
* | |
*/ | |
package sandbox.atomic; | |
import java.util.List; | |
import java.util.Set; | |
import java.util.concurrent.Callable; | |
import java.util.concurrent.CyclicBarrier; | |
import java.util.concurrent.ExecutorService; |
This file contains 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
package hobby; | |
/** | |
* 疑似 Option 型です。 | |
* | |
* @author monzou | |
* @param <T> 要素の型 | |
*/ | |
public interface Option<T> { |
This file contains 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 RowParser | |
PATTERN = /^\s*([0-9]+)(\s*)(.*)\(cr=(\d+) r=(\d+) w=(\d+) time=(\d+)/ | |
KEYS = [ :ROW, :INDENT, :OPERATION, :CR, :R, :W, :TIME ] | |
def parse(line) | |
tokens = line.scan(PATTERN)[0] | |
format(Hash[*([ KEYS, tokens ].transpose).flatten]) unless tokens.nil? | |
end |