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
<?php | |
class Renge { | |
public function __construct($params = ['seed' => NULL, 'delimiter' => NULL]) { | |
$this->seed = $params['seed']; | |
$this->delimiter = $params['delimiter']; | |
} | |
public function encode($string) { | |
$table = $this->convert_table(['for' => 'encode']); | |
foreach ($this->unpack_U($string) as $char) { |
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 C | |
attr_accessor :age | |
def initialize(&block) | |
instance_eval(&block) | |
end | |
def name(string) | |
@name = string | |
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
require 'open_jtalk' | |
require 'tmpdir' | |
require 'readline' | |
class Talk | |
def start | |
tmpdir = Dir.mktmpdir('syaberu.rb') | |
while string = Readline.readline('> ', true) | |
say(string, tmpdir) | |
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
# ロガーライブラリをロード | |
require 'logger' | |
module AwesomeGem | |
# ロガーを定義 | |
# ログは標準エラー出力(STDERR)へ出力される | |
@@log ||= Logger.new(STDERR).tap do |log| | |
# ログに記録されるアプリケーション名 | |
log.progname = 'AwesomeGem' |
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
require 'n_cipher/argument_validation' | |
class Configuration | |
include NCipher::ArgumentValidation | |
def initialize(hash, &block) | |
hash.each(&method(:set_attribute)) | |
hash.each(&method(:define_accessor)) | |
define_reseter(hash) | |
yield(self) if block_given? |
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
require 'n_cipher/argument_validation' | |
class Configuration | |
include NCipher::ArgumentValidation | |
def initialize(hash) | |
hash.each_pair(&method(:define_accessor)) | |
define_singleton_method(:reset) { initialize(hash); self } | |
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
#!/usr/bin/env ruby | |
require 'optparse' | |
require 'logger' | |
Version = 'v0.1.0' | |
Release = '2016-02-07' | |
Signal.trap(:INT) { exit(1) } | |
logger = Logger.new(STDERR) |
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
require 'pp' | |
data = DATA.each_with_object(Struct.new(:speaker, :quote)).map {|line, quote| | |
r = line.split("\t").map {|pair| pair.chomp.split(':') }.to_h | |
quote.new(r['speaker'], r['quote']) | |
} | |
pp data | |
.group_by {|row| row.quote[-1] } | |
.map {|group| group[1].map!(&:quote); group } |
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
puts DATA.map(&:chomp).sample | |
__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
殺人 =-> したこと { したこと =~ /殺人/ } | |
殺人じゃないやつ =-> したこと { 殺人.(したこと).! } | |
その子何したんだろうね? =-> したこと { | |
case したこと | |
when 殺人 | |
'アホか!むしろ怒れるか!' | |
when 殺人じゃないやつ | |
'広い!' | |
end |