4-3-2 オブジェクトへの変更を禁止する

In [2]:
o = Object.new
o.freeze
o.frozen?
Out[2]:
true
In [3]:
o2 = Object.new
o2.frozen?
Out[3]:
false
In [4]:
str = "hoge"
str.frozen?
Out[4]:
false
In [5]:
str << "2"
Out[5]:
"hoge2"
In [6]:
str.freeze
str << "0"
RuntimeError: can't modify frozen String
(pry):12:in `<main>'
/Users/mic/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/pry-0.10.1/lib/pry/pry_instance.rb:355:in `eval'
/Users/mic/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/pry-0.10.1/lib/pry/pry_instance.rb:355:in `evaluate_ruby'
/Users/mic/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/pry-0.10.1/lib/pry/pry_instance.rb:323:in `handle_line'
/Users/mic/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/pry-0.10.1/lib/pry/pry_instance.rb:243:in `block (2 levels) in eval'
/Users/mic/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/pry-0.10.1/lib/pry/pry_instance.rb:242:in `catch'
/Users/mic/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/pry-0.10.1/lib/pry/pry_instance.rb:242:in `block in eval'
/Users/mic/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/pry-0.10.1/lib/pry/pry_instance.rb:241:in `catch'
/Users/mic/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/pry-0.10.1/lib/pry/pry_instance.rb:241:in `eval'
/Users/mic/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/iruby-0.2.7/lib/iruby/backend.rb:65:in `eval'
/Users/mic/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/iruby-0.2.7/lib/iruby/backend.rb:12:in `eval'
/Users/mic/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/iruby-0.2.7/lib/iruby/kernel.rb:87:in `execute_request'
/Users/mic/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/iruby-0.2.7/lib/iruby/kernel.rb:47:in `dispatch'
/Users/mic/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/iruby-0.2.7/lib/iruby/kernel.rb:37:in `run'
/Users/mic/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/iruby-0.2.7/lib/iruby/command.rb:70:in `run_kernel'
/Users/mic/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/iruby-0.2.7/lib/iruby/command.rb:34:in `run'
/Users/mic/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/iruby-0.2.7/bin/iruby:5:in `<top (required)>'
/Users/mic/.rbenv/versions/2.2.2/bin/iruby:23:in `load'
/Users/mic/.rbenv/versions/2.2.2/bin/iruby:23:in `<main>'

.frreezeしても代入は出来てしまう

In [7]:
DEFAULT_CONST = {foo: 123}.freeze
DEFAULT_CONST = {foo: 234}
(pry):14: warning: already initialized constant DEFAULT_CONST
(pry):13: warning: previous definition of DEFAULT_CONST was here
Out[7]:
{:foo=>234}
In [8]:
DEFAULT_CONST.frozen?
Out[8]:
false
In [9]:
DEFAULT_CONST.freeze
DEFAULT_CONST.frozen?
Out[9]:
true

Hashの中身は変更できない

In [10]:
DEFAULT_CONST[:foo] = 2
RuntimeError: can't modify frozen Hash
(pry):18:in `<main>'
/Users/mic/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/pry-0.10.1/lib/pry/pry_instance.rb:355:in `eval'
/Users/mic/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/pry-0.10.1/lib/pry/pry_instance.rb:355:in `evaluate_ruby'
/Users/mic/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/pry-0.10.1/lib/pry/pry_instance.rb:323:in `handle_line'
/Users/mic/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/pry-0.10.1/lib/pry/pry_instance.rb:243:in `block (2 levels) in eval'
/Users/mic/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/pry-0.10.1/lib/pry/pry_instance.rb:242:in `catch'
/Users/mic/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/pry-0.10.1/lib/pry/pry_instance.rb:242:in `block in eval'
/Users/mic/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/pry-0.10.1/lib/pry/pry_instance.rb:241:in `catch'
/Users/mic/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/pry-0.10.1/lib/pry/pry_instance.rb:241:in `eval'
/Users/mic/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/iruby-0.2.7/lib/iruby/backend.rb:65:in `eval'
/Users/mic/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/iruby-0.2.7/lib/iruby/backend.rb:12:in `eval'
/Users/mic/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/iruby-0.2.7/lib/iruby/kernel.rb:87:in `execute_request'
/Users/mic/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/iruby-0.2.7/lib/iruby/kernel.rb:47:in `dispatch'
/Users/mic/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/iruby-0.2.7/lib/iruby/kernel.rb:37:in `run'
/Users/mic/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/iruby-0.2.7/lib/iruby/command.rb:70:in `run_kernel'
/Users/mic/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/iruby-0.2.7/lib/iruby/command.rb:34:in `run'
/Users/mic/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/iruby-0.2.7/bin/iruby:5:in `<top (required)>'
/Users/mic/.rbenv/versions/2.2.2/bin/iruby:23:in `load'
/Users/mic/.rbenv/versions/2.2.2/bin/iruby:23:in `<main>'
In [11]:
FROZEN_INT = 3
FROZEN_INT.freeze
FROZEN_INT += 3
(pry):21: warning: already initialized constant FROZEN_INT
(pry):19: warning: previous definition of FROZEN_INT was here
Out[11]:
6
In [12]:
:foo = 3
:foo
:foo.frozen?
SyntaxError: unexpected '=', expecting end-of-input
:foo = 3
      ^
In [13]:
:foo.extend Enumerable
TypeError: can't define singleton
(pry):22:in `extend_object'
(pry):22:in `extend'
(pry):22:in `<main>'
/Users/mic/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/pry-0.10.1/lib/pry/pry_instance.rb:355:in `eval'
/Users/mic/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/pry-0.10.1/lib/pry/pry_instance.rb:355:in `evaluate_ruby'
/Users/mic/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/pry-0.10.1/lib/pry/pry_instance.rb:323:in `handle_line'
/Users/mic/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/pry-0.10.1/lib/pry/pry_instance.rb:243:in `block (2 levels) in eval'
/Users/mic/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/pry-0.10.1/lib/pry/pry_instance.rb:242:in `catch'
/Users/mic/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/pry-0.10.1/lib/pry/pry_instance.rb:242:in `block in eval'
/Users/mic/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/pry-0.10.1/lib/pry/pry_instance.rb:241:in `catch'
/Users/mic/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/pry-0.10.1/lib/pry/pry_instance.rb:241:in `eval'
/Users/mic/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/iruby-0.2.7/lib/iruby/backend.rb:65:in `eval'
/Users/mic/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/iruby-0.2.7/lib/iruby/backend.rb:12:in `eval'
/Users/mic/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/iruby-0.2.7/lib/iruby/kernel.rb:87:in `execute_request'
/Users/mic/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/iruby-0.2.7/lib/iruby/kernel.rb:47:in `dispatch'
/Users/mic/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/iruby-0.2.7/lib/iruby/kernel.rb:37:in `run'
/Users/mic/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/iruby-0.2.7/lib/iruby/command.rb:70:in `run_kernel'
/Users/mic/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/iruby-0.2.7/lib/iruby/command.rb:34:in `run'
/Users/mic/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/iruby-0.2.7/bin/iruby:5:in `<top (required)>'
/Users/mic/.rbenv/versions/2.2.2/bin/iruby:23:in `load'
/Users/mic/.rbenv/versions/2.2.2/bin/iruby:23:in `<main>'

4-3-3 オブジェクトをコピーする

In [14]:
original = Object.new
original.object_id
Out[14]:
70282404920840
In [15]:
original.freeze
copy_dup = original.dup
p copy_dup.object_id
copy_dup.frozen?
70282396473120
Out[15]:
false
In [16]:
copy_clone = original.clone
p copy_clone.object_id
copy_clone.frozen?
70282404790600
Out[16]:
true
In [17]:
value = 'foo'
array = [value]
array_dup = array.dup
array_clone = array.clone
p value.object_id
p array_dup.first.object_id
p array_clone.first.object_id
70282408680320
70282408680320
70282408680320
Out[17]:
70282408680320
In [18]:
p array
p array_dup
["foo"]
["foo"]
Out[18]:
["foo"]
In [19]:
array_dup[0] = "bar"
p array_dup
p array
["bar"]
["foo"]
Out[19]:
["foo"]
In [20]:
array_dup = array.dup
array_dup
array_dup[0] << '2'
p array_dup
array
["foo2"]
Out[20]:
["foo2"]

安全にdeep copyするならMarshal.dump, Marshal.loadするのも一つの方法

In [21]:
Marshal.dump(array)
array_dump= Marshal.load(Marshal.dump(array))
array_dump.first.object_id
Out[21]:
70282409381020
In [22]:
array.first.object_id
Out[22]:
70282408680320
In [23]:
array_dump[0] << '0'
p array_dump
array
["foo20"]
Out[23]:
["foo2"]

4-3-4 汚染されたオブジェクト

pryとirubyの挙動が違う...

In [24]:
$SAFE
Out[24]:
0
In [25]:
Object.new.tainted?
Out[25]:
false
In [26]:
ENV['HOME'].tainted?
Out[26]:
true
In [27]:
o = Object.new
p o.tainted?
o.taint
p o.tainted?
false
true
Out[27]:
true
In [28]:
rcfile = ENV['HOME'] + '/.zshrc'
rcfile.tainted?
Out[28]:
true
In [29]:
$SAFE = 1
Out[29]:
1
In [30]:
$SAFE
Out[30]:
1
In [31]:
test_file = ENV['HOME'] + '/test_file'
Out[31]:
"/Users/mic/test_file"
In [32]:
ENV['HOME'].class
Out[32]:
String
In [33]:
ENV['HOME'].tainted?
Out[33]:
true

5章 主な組込みクラス/モジュール

5-1 Numeric

In [34]:
p Integer.ancestors
p Float.ancestors
p Rational.ancestors
p Complex.ancestors
p Fixnum.ancestors
Bignum.ancestors
[Integer, Numeric, Comparable, Object, PP::ObjectMixin, Kernel, BasicObject]
[Float, Numeric, Comparable, Object, PP::ObjectMixin, Kernel, BasicObject]
[Rational, Numeric, Comparable, Object, PP::ObjectMixin, Kernel, BasicObject]
[Complex, Numeric, Comparable, Object, PP::ObjectMixin, Kernel, BasicObject]
[Fixnum, Integer, Numeric, Comparable, Object, PP::ObjectMixin, Kernel, BasicObject]
Out[34]:
[Bignum, Integer, Numeric, Comparable, Object, PP::ObjectMixin, Kernel, BasicObject]
In [38]:
p 0.zero?
p 3.zero?
true
false
Out[38]:
false
In [39]:
ary = [1, 0, 3]
p ary.select(&:zero?)
p ary.reject(&:zero?)
ary.select(&:nonzero?)
[0]
[1, 3]
Out[39]:
[1, 3]
In [41]:
p 365.integer?
p 36.5.integer?
p 36.5.numeric?
true
false
NoMethodError: undefined method `numeric?' for 36.5:Float
(pry):100:in `<main>'
/Users/mic/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/pry-0.10.1/lib/pry/pry_instance.rb:355:in `eval'
/Users/mic/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/pry-0.10.1/lib/pry/pry_instance.rb:355:in `evaluate_ruby'
/Users/mic/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/pry-0.10.1/lib/pry/pry_instance.rb:323:in `handle_line'
/Users/mic/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/pry-0.10.1/lib/pry/pry_instance.rb:243:in `block (2 levels) in eval'
/Users/mic/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/pry-0.10.1/lib/pry/pry_instance.rb:242:in `catch'
/Users/mic/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/pry-0.10.1/lib/pry/pry_instance.rb:242:in `block in eval'
/Users/mic/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/pry-0.10.1/lib/pry/pry_instance.rb:241:in `catch'
/Users/mic/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/pry-0.10.1/lib/pry/pry_instance.rb:241:in `eval'
/Users/mic/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/iruby-0.2.7/lib/iruby/backend.rb:65:in `eval'
/Users/mic/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/iruby-0.2.7/lib/iruby/backend.rb:12:in `eval'
/Users/mic/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/iruby-0.2.7/lib/iruby/kernel.rb:87:in `execute_request'
/Users/mic/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/iruby-0.2.7/lib/iruby/kernel.rb:47:in `dispatch'
/Users/mic/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/iruby-0.2.7/lib/iruby/kernel.rb:37:in `run'
/Users/mic/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/iruby-0.2.7/lib/iruby/command.rb:70:in `run_kernel'
/Users/mic/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/iruby-0.2.7/lib/iruby/command.rb:34:in `run'
/Users/mic/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/iruby-0.2.7/bin/iruby:5:in `<top (required)>'
/Users/mic/.rbenv/versions/2.2.2/bin/iruby:23:in `load'
/Users/mic/.rbenv/versions/2.2.2/bin/iruby:23:in `<main>'
In [43]:
p 36.5.real?
p 100.bignum?
true
NoMethodError: undefined method `bignum?' for 100:Fixnum
(pry):105:in `<main>'
/Users/mic/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/pry-0.10.1/lib/pry/pry_instance.rb:355:in `eval'
/Users/mic/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/pry-0.10.1/lib/pry/pry_instance.rb:355:in `evaluate_ruby'
/Users/mic/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/pry-0.10.1/lib/pry/pry_instance.rb:323:in `handle_line'
/Users/mic/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/pry-0.10.1/lib/pry/pry_instance.rb:243:in `block (2 levels) in eval'
/Users/mic/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/pry-0.10.1/lib/pry/pry_instance.rb:242:in `catch'
/Users/mic/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/pry-0.10.1/lib/pry/pry_instance.rb:242:in `block in eval'
/Users/mic/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/pry-0.10.1/lib/pry/pry_instance.rb:241:in `catch'
/Users/mic/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/pry-0.10.1/lib/pry/pry_instance.rb:241:in `eval'
/Users/mic/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/iruby-0.2.7/lib/iruby/backend.rb:65:in `eval'
/Users/mic/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/iruby-0.2.7/lib/iruby/backend.rb:12:in `eval'
/Users/mic/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/iruby-0.2.7/lib/iruby/kernel.rb:87:in `execute_request'
/Users/mic/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/iruby-0.2.7/lib/iruby/kernel.rb:47:in `dispatch'
/Users/mic/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/iruby-0.2.7/lib/iruby/kernel.rb:37:in `run'
/Users/mic/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/iruby-0.2.7/lib/iruby/command.rb:70:in `run_kernel'
/Users/mic/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/iruby-0.2.7/lib/iruby/command.rb:34:in `run'
/Users/mic/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/iruby-0.2.7/bin/iruby:5:in `<top (required)>'
/Users/mic/.rbenv/versions/2.2.2/bin/iruby:23:in `load'
/Users/mic/.rbenv/versions/2.2.2/bin/iruby:23:in `<main>'
In [44]:
p Complex(1, 2).real?
false
Out[44]:
false

5-1-1 算術演算

In [46]:
p 10 /3
p 10.0 /3
num = 10
p num / 3
num.to_f / 3
3
3.3333333333333335
3
Out[46]:
3.3333333333333335

5-1-2 比較演算

In [47]:
123 == 123.0
Out[47]:
true

5-1-3 丸め操作

In [48]:
p 1.4.round
p 1.5.round
p -1.5.round
1
2
-2
Out[48]:
-2
In [49]:
p 1.4.ceil
p 1.5.ceil
p -1.5.ceil
p -1.4.ceil
2
2
-1
-1
Out[49]:
-1
In [50]:
p 1.5.floor
p 1.4.floor
p -1.4.floor
1
1
-2
Out[50]:
-2
In [52]:
p 1.5.truncate
p -1.5.truncate
p 1.6.truncate
p 1.7.truncate
p 1.9.truncate
p -0.9.truncate
p -1.9.truncate
1
-1
1
1
1
0
-1
Out[52]:
-1

5-1-4 繰り返し処理

In [53]:
3.step 5 do |num|
  puts num
end
3
4
5
Out[53]:
3
In [54]:
1.2.step 2.0, 0.2 do |num|
  puts num
end
1.2
1.4
1.6
1.8
2.0
Out[54]:
1.2
In [55]:
3.upto(5) do |num|
  puts num
end
3
4
5
Out[55]:
3
In [56]:
3.upto(10, 2) do |num|
  puts num
end
ArgumentError: wrong number of arguments (2 for 1)
(pry):153:in `upto'
(pry):153:in `<main>'
/Users/mic/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/pry-0.10.1/lib/pry/pry_instance.rb:355:in `eval'
/Users/mic/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/pry-0.10.1/lib/pry/pry_instance.rb:355:in `evaluate_ruby'
/Users/mic/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/pry-0.10.1/lib/pry/pry_instance.rb:323:in `handle_line'
/Users/mic/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/pry-0.10.1/lib/pry/pry_instance.rb:243:in `block (2 levels) in eval'
/Users/mic/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/pry-0.10.1/lib/pry/pry_instance.rb:242:in `catch'
/Users/mic/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/pry-0.10.1/lib/pry/pry_instance.rb:242:in `block in eval'
/Users/mic/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/pry-0.10.1/lib/pry/pry_instance.rb:241:in `catch'
/Users/mic/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/pry-0.10.1/lib/pry/pry_instance.rb:241:in `eval'
/Users/mic/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/iruby-0.2.7/lib/iruby/backend.rb:65:in `eval'
/Users/mic/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/iruby-0.2.7/lib/iruby/backend.rb:12:in `eval'
/Users/mic/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/iruby-0.2.7/lib/iruby/kernel.rb:87:in `execute_request'
/Users/mic/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/iruby-0.2.7/lib/iruby/kernel.rb:47:in `dispatch'
/Users/mic/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/iruby-0.2.7/lib/iruby/kernel.rb:37:in `run'
/Users/mic/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/iruby-0.2.7/lib/iruby/command.rb:70:in `run_kernel'
/Users/mic/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/iruby-0.2.7/lib/iruby/command.rb:34:in `run'
/Users/mic/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/iruby-0.2.7/bin/iruby:5:in `<top (required)>'
/Users/mic/.rbenv/versions/2.2.2/bin/iruby:23:in `load'
/Users/mic/.rbenv/versions/2.2.2/bin/iruby:23:in `<main>'
In [57]:
1.3.upto(2.0) do |num|
  puts
end
NoMethodError: undefined method `upto' for 1.3:Float
(pry):156:in `<main>'
/Users/mic/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/pry-0.10.1/lib/pry/pry_instance.rb:355:in `eval'
/Users/mic/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/pry-0.10.1/lib/pry/pry_instance.rb:355:in `evaluate_ruby'
/Users/mic/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/pry-0.10.1/lib/pry/pry_instance.rb:323:in `handle_line'
/Users/mic/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/pry-0.10.1/lib/pry/pry_instance.rb:243:in `block (2 levels) in eval'
/Users/mic/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/pry-0.10.1/lib/pry/pry_instance.rb:242:in `catch'
/Users/mic/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/pry-0.10.1/lib/pry/pry_instance.rb:242:in `block in eval'
/Users/mic/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/pry-0.10.1/lib/pry/pry_instance.rb:241:in `catch'
/Users/mic/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/pry-0.10.1/lib/pry/pry_instance.rb:241:in `eval'
/Users/mic/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/iruby-0.2.7/lib/iruby/backend.rb:65:in `eval'
/Users/mic/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/iruby-0.2.7/lib/iruby/backend.rb:12:in `eval'
/Users/mic/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/iruby-0.2.7/lib/iruby/kernel.rb:87:in `execute_request'
/Users/mic/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/iruby-0.2.7/lib/iruby/kernel.rb:47:in `dispatch'
/Users/mic/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/iruby-0.2.7/lib/iruby/kernel.rb:37:in `run'
/Users/mic/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/iruby-0.2.7/lib/iruby/command.rb:70:in `run_kernel'
/Users/mic/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/iruby-0.2.7/lib/iruby/command.rb:34:in `run'
/Users/mic/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/iruby-0.2.7/bin/iruby:5:in `<top (required)>'
/Users/mic/.rbenv/versions/2.2.2/bin/iruby:23:in `load'
/Users/mic/.rbenv/versions/2.2.2/bin/iruby:23:in `<main>'

次回は、5-1-5 Integerから

In [ ]: