https://github.com/ledermann/unread
全体像
├── .gemtags
├── .gitignore
├── .tags
├── .tags_sorted_by_file
├── .travis.yml
class ProducerConsumer | |
KILL = :kill | |
def initialize(produce:, consume:, producer_num: 1, consumer_num: 5, max_queue_size: 1000) | |
@produce = produce | |
@consume = consume | |
@consumer_num = consumer_num | |
@producer_num = producer_num | |
@ids_index = 0 | |
@max_queue_size = max_queue_size |
# バックナンバー | |
### Rubyわくわくナビ | |
- 2012-66:Bundlerを使いこなす! | |
- 2012-67:厳選!用途別Ruby/Railsライブラリツール | |
- 2012-68:データで見るRubyGemsの世界 | |
### 一歩先をゆくRuby |
// 環境 node v4.1.2 | |
// 実行せず出力結果を記述しなさい | |
console.log(typeof 'foo'); | |
console.log(typeof new Object()); | |
console.log(typeof undefined); | |
console.log(typeof new Function('x', 'y', 'return x * y')); | |
console.log(typeof true); | |
console.log(typeof /abc/g); | |
console.log(typeof String('hoge')); | |
console.log(typeof 10); |
https://github.com/ledermann/unread
全体像
├── .gemtags
├── .gitignore
├── .tags
├── .tags_sorted_by_file
├── .travis.yml
[1] pry(main)> class Base | |
[1] pry(main)* cattr_accessor :setting2 | |
[1] pry(main)* end | |
=> [:setting2] | |
[2] pry(main)> class Subclass < Base ; end | |
=> nil | |
[3] pry(main)> Base.setting2 | |
=> nil | |
[4] pry(main)> Base.setting2 = true |
(User.hoges || []).each do |hoge| | |
hoge.fuga! | |
end |
class MutableConstant | |
SERVICE_TYPES1 = ["basic", "premium", "pro"] | |
SERVICE_TYPES2 = ["basic", "premium", "pro"].freeze | |
SERVICE_TYPES3 = ["basic", "premium", "pro"].map(&:freeze).freeze | |
module Defaults | |
SERVICE_TYPES1 = ["basic", "premium", "pro"] | |
SERVICE_TYPES2 = ["basic", "premium", "pro"].freeze | |
SERVICE_TYPES3 = ["basic", "premium", "pro"].map(&:freeze).freeze | |
end |
#!/usr/bin/env ruby | |
require "webrick" | |
=begin | |
WEBrick is a Ruby library that makes it easy to build an HTTP server with Ruby. | |
It comes with most installations of Ruby by default (it’s part of the standard library), | |
so you can usually create a basic web/HTTP server with only several lines of code. | |
The following code creates a generic WEBrick server on the local machine on port 1234, |
Enumable#grep | |
レシーバと引数が===と一致するかどうかで絞り込む | |
# ===で一致するか、ということは==の条件に「範囲ないか」「インスタンス、クラスに属するか」「正規表現に一致するか」は加わったもの | |
(1..10).grep(2..3) #=> [2, 3] | |
%w|a 1 * @|.grep(/[1-9]/) #=> ["1"] | |
["a", 1, "&", "@"].grep(Integer) #=> [1] | |
grepの良い所は条件でしぼりこんだあとにブロックを渡して更に処理ができる |
Hash#find_all | |
Hash#select | |
h = {a: 1, b: 2, c: 3} | |
h.find_all { |key, value| value.odd? } #=> [[:a, 1], [:c, 3]] | |
h.select { |key, value| value.odd? } #=> {:a=>1, :c=>3} | |
Array#select | |
Array#select |