typesafe_enum 0.1.5 → 0.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4528ca4b1564d3a5ec9d24574a01347e3c722a64
4
- data.tar.gz: cb8329c1159be1527dae44c527a4137887cdd9e3
3
+ metadata.gz: 7d4eb09d4f1aa7e839ff17914b2b41273e5f82ef
4
+ data.tar.gz: 863e13f1b183a106aa9ad565485f2cb07ef6bac6
5
5
  SHA512:
6
- metadata.gz: 096ca0c3cac38232d29392d42648bd23d28e68faa18ecceaaa249601132f975185bd1fb2e5c9237d1729b2f889fa8087c851785cd035ab2ddb5829c7f9166f11
7
- data.tar.gz: 6706fe40b8e449bef7061281691dc0cfe18f92df421f866baf2e59db093410d0f5cb197b1d6af993fc2fa6105a03e06331127007b9547e997c6da63d1520cd17
6
+ metadata.gz: 952de3b215c8a70054d644b82003069a12f85880d91645456b6a681f94f0d952820cf73db32e1563359d53846117c8cc12ce6864a6573d3094390a2bd98ca2ce
7
+ data.tar.gz: 0e9f424f975ad48bcbab6aaf6719082319e3a593f5372ada6eb9694b330b9679ecf9556c72c0c602e135911956857c150efcb340bfba4f34dc00ec6ec087fe2e
data/CHANGES.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 0.1.6 (15 Mar 2016)
2
+
3
+ - [#3](https://github.com/dmolesUC3/typesafe_enum/pull/3) - No need for `instance_eval` when creating new enum instance methods - [@dblock](https://github.com/dblock).
4
+
1
5
  ## 0.1.5 (27 Jan 2016)
2
6
 
3
7
  - Include the original call site in the warning message for duplicate instances to help
data/README.md CHANGED
@@ -264,16 +264,16 @@ Suit.map(&:pip)
264
264
 
265
265
  ## Enum instances with methods
266
266
 
267
- Enum instances can declare their own methods via `instance_eval`:
267
+ Enum instances can declare their own methods:
268
268
 
269
269
  ```ruby
270
270
  class Operation < TypesafeEnum::Base
271
- new(:PLUS, '+').instance_eval do
271
+ new(:PLUS, '+') do
272
272
  def eval(x, y)
273
273
  x + y
274
274
  end
275
275
  end
276
- new(:MINUS, '-').instance_eval do
276
+ new(:MINUS, '-') do
277
277
  def eval(x, y)
278
278
  x - y
279
279
  end
@@ -370,7 +370,7 @@ enum Suit {
370
370
  }
371
371
  ```
372
372
 
373
- With `TypesafeEnum`, instance-specific methods require extra parentheses and `instance_eval`,
373
+ With `TypesafeEnum`, instance-specific methods require extra parentheses,
374
374
  as shown above, and about the best you can do even for simple enums is something like:
375
375
 
376
376
  ```ruby
@@ -119,13 +119,14 @@ module TypesafeEnum
119
119
 
120
120
  private
121
121
 
122
- def initialize(key, value = nil)
122
+ def initialize(key, value = nil, &block)
123
123
  fail TypeError, "#{key} is not a symbol" unless key.is_a?(Symbol)
124
124
  @key = key
125
125
  @value = value || key.to_s.downcase
126
126
  @ord = self.class.size
127
127
  self.class.class_exec(self) do |instance|
128
128
  register(instance)
129
+ instance.instance_eval(&block) if block_given?
129
130
  end
130
131
  end
131
132
 
@@ -3,7 +3,7 @@ module TypesafeEnum
3
3
  NAME = 'typesafe_enum'
4
4
 
5
5
  # The version of this gem
6
- VERSION = '0.1.5'
6
+ VERSION = '0.1.6'
7
7
 
8
8
  # The copyright notice for this gem
9
9
  COPYRIGHT = 'Copyright (c) 2016 The Regents of the University of California'
@@ -1,4 +1,4 @@
1
- # coding: UTF-8
1
+ # coding: utf-8
2
2
  require 'spec_helper'
3
3
 
4
4
  class Suit < TypesafeEnum::Base
@@ -361,7 +361,6 @@ module TypesafeEnum
361
361
  end
362
362
 
363
363
  describe '::find_by_ord' do
364
-
365
364
  it 'maps ordinal indices to enum instances' do
366
365
  Suit.each do |s|
367
366
  expect(Suit.find_by_ord(s.ord)).to be(s)
@@ -400,14 +399,14 @@ module TypesafeEnum
400
399
  expect(Suit.map { |s| pip(s) }).to eq(%w(♣ ♦ ♥ ♠))
401
400
  end
402
401
 
403
- it 'supports "inner class" methods via instance_eval' do
404
- class ::Operation < Base
405
- new(:PLUS, '+').instance_eval do
402
+ it 'supports "inner class" methods' do
403
+ class Operation < Base
404
+ new(:PLUS, '+') do
406
405
  def eval(x, y)
407
406
  x + y
408
407
  end
409
408
  end
410
- new(:MINUS, '-').instance_eval do
409
+ new(:MINUS, '-') do
411
410
  def eval(x, y)
412
411
  x - y
413
412
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: typesafe_enum
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Moles
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-01-27 00:00:00.000000000 Z
11
+ date: 2016-03-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler