3分の1の研究 といった また さらに 認める 彼らはむしろ 睡眠 しながら と比較して 男性 壊滅的な
Array()
引数を配列(Array)に変換した結果を返します。
arg.to_ary と arg.to_a をこの順に呼び出して、返ってきた配列を変換結果とします。
arg に to_ary, to_a のいずれのメソッドも定義されていない場合は 一要素の配列 [arg] を返します。
- [PARAM] arg:
- 変換対象のオブジェクトです。
- [EXCEPTION] TypeError:
- to_ary, to_a の返り値が配列でなければ発生します
p Array({:it => 3}) #=> [[:it, 3]]
p Array(nil) #=> []
p Array("fefe") #=> ["fefe"]
require 'forwardable'
class Foo
extend Forwardable
def_delegators("@out", "printf", "print")
def_delegators(:@in, :gets)
def_delegator(:@contents, :[], "content_at")
end
f = Foo.new
f.printf ...
f.gets
f.content_at(1)
require "observer"
class Ticker ### Periodically fetch a stock price.
include Observable
def initialize(symbol)
@symbol = symbol
end
def run
last_price = nil
loop do
price = Price.fetch(@symbol)
print "Current price: #{price}\n"
if price != last_price
changed # notify observers
last_price = price
notify_observers(Time.now, price)
end
sleep 1
end
end
end
class Price ### A mock class to fetch a stock price (60 - 140).
def self.fetch(symbol)
60 + rand(80)
end
end
class Warner ### An abstract observer of Ticker objects.
def initialize(ticker, limit)
@limit = limit
ticker.add_observer(self)
end
end
class WarnLow < Warner
def update(time, price) # callback for observer
if price < @limit
print "--- #{time.to_s}: Price below #@limit: #{price}\n"
end
end
end
class WarnHigh < Warner
def update(time, price) # callback for observer
if price > @limit
print "+++ #{time.to_s}: Price above #@limit: #{price}\n"
end
end
end
ticker = Ticker.new("MSFT")
WarnLow.new(ticker, 80)
WarnHigh.new(ticker, 120)
ticker.run
# => Current price: 126
# => +++ 2017-11-02 12:09:36 +0900: Price above 120: 126
# => Current price: 102
# => Current price: 87
# => Current price: 121
ipconfig
ip:3000
ip(xampp)
Webrick()
|
function no_name_callback(){ return "侍エンジニア塾"; }
// ②コールバック関数を実行する関数 function no_name($callback){ echo $callback(). "です"; }
// ③関数を実行、コールバック関数を渡す no_name("no_name_callback"); |
-----------------------------------------------------------------
study find one third such as moreover further admit they would rather sleep while likely to compared to male devastated