its-it 1.1.1 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 0940411f44c31b8869ba17e8efa1505c63c01c97
4
+ data.tar.gz: 3a0b78717605b167e8017b4d9108f6cb08a3b680
5
+ SHA512:
6
+ metadata.gz: f0a011722987ec5ac5a566c23e54c869a9faadec3a036cf3f207e9b92a32078527a25a06409668941706e490dfdfa011a5d2d8111603fe385bde91b7e2b3a4d0
7
+ data.tar.gz: a386fe0ed1440033d01c5a794ff447892225bcdf98e610c66d14a7324085e42458741809107f7d00c6b7a1d6bd116363c11a1c94c9d483bbd454767f6639501d
data/.rspec CHANGED
@@ -1 +1,2 @@
1
1
  --color
2
+ --format d
@@ -0,0 +1,5 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 2.0.0
5
+ - 2.2.3
@@ -0,0 +1,148 @@
1
+ # its-it
2
+
3
+
4
+ ## Overview
5
+
6
+ This gem defines kernel methods `its` and `it` that queue and defer method
7
+ calls. This is handy for list comprehension and case statements.
8
+
9
+ [![Gem Version](https://badge.fury.io/rb/its-it.png)](http://badge.fury.io/rb/its-it)
10
+ [![Build Status](https://secure.travis-ci.org/ronen/its-it.png)](http://travis-ci.org/ronen/its-it)
11
+ [![Dependency Status](https://gemnasium.com/ronen/its-it.png)](https://gemnasium.com/ronen/its-it)
12
+
13
+ ## List Comprehension
14
+
15
+ `its` and `it` extend the Symbol#to_proc idiom to support chaining multiple
16
+ methods.
17
+
18
+ The pure Ruby way to chain methods when iterating through a list would be:
19
+
20
+ ```ruby
21
+ users.map{|user| user.contact}.map{|contact| contact.last_name}.map{|name| name.capitalize}
22
+ ```
23
+
24
+ Using `Symbol#to_proc`, this becomes simpler (at the cost of generating intermediate arrays):
25
+
26
+ ```ruby
27
+ users.map(&:contact).map(&:last_name).map(&:capitalize)
28
+ ```
29
+
30
+ And using `its`, this becomes becomes simpler still:
31
+
32
+ ```ruby
33
+ users.map(&its.contact.last_name.capitalize)
34
+ ```
35
+
36
+ Note that `its` captures arguments and blocks, allowing you to do things like
37
+
38
+ ```ruby
39
+ users.map(&its.contact.last_name[0,3].capitalize)
40
+ ```
41
+
42
+ or
43
+
44
+ ```ruby
45
+ users.select(&its.addresses.any? { |address| airline.flies_to address.city })
46
+ ```
47
+
48
+
49
+ `it` is an alias for `its`, to use with methods that describe actions rather
50
+ than posessives. For example:
51
+
52
+ ```ruby
53
+ items.map(&it.to_s.capitalize)
54
+ ```
55
+
56
+ When used with hash comprehensions, the `|key, val|` pair of arguments are presented to `its` as an array. E.g.
57
+
58
+ ```ruby
59
+ {dogs: 1, cats: 2, goats:3}.select &it[1].even? # => {cats: 2}
60
+ ```
61
+
62
+ ## Case statements
63
+
64
+ `its` and `it` likewise extend Ruby's `case` statement to support testing
65
+ arbitrary methods, minimizing the need to create temporary variables and use
66
+ `if-elsif` constructs.
67
+
68
+ In pure Ruby, doing comparisons on computed values would be done something
69
+ like this:
70
+
71
+ ```ruby
72
+ maxlen = arrays.map(&size).max
73
+ if maxlen > 10000
74
+ "too big"
75
+ elsif maxlen < 10
76
+ "too small"
77
+ else
78
+ "okay"
79
+ end
80
+ ```
81
+
82
+ But using `it` this becomes:
83
+
84
+ ```ruby
85
+ case arrays.map(&size).max
86
+ when it > 1000
87
+ "too big"
88
+ when it < 10
89
+ "too small"
90
+ else
91
+ "okay"
92
+ end
93
+ ```
94
+
95
+ Of course method chanining can be used here too:
96
+
97
+ ```ruby
98
+ case users.first
99
+ when its.name == "Gimme Cookie" then ...
100
+ when its.name.length > 10 then ...
101
+ else ...
102
+ end
103
+ ```
104
+
105
+ ## Under the hood
106
+
107
+ The `ItsIt::It` class uses `method_missing` to capture and queue up all
108
+ methods and their arguments, with the exception of `:to_proc` and `:===` (and
109
+ also excepting `:respond_to? :to_proc` and `:respond_to? :===`).
110
+
111
+ `:to_proc` returns a proc that will evaluate the method queue on a given
112
+ argument. `:===` takes an argument and evaluates that proc, returning the
113
+ result.
114
+
115
+ ## Installation
116
+
117
+ Install as usual from http://rubygems.org via
118
+
119
+ ```bash
120
+ $ gem install "its-it"
121
+ ```
122
+
123
+ or in a Gemfile
124
+
125
+ ```ruby
126
+ gem "its-it"
127
+ ```
128
+
129
+ ## Compatibility
130
+
131
+ Tested on MRI ruby 1.9.3, 2.0.0 and 2.2.3
132
+
133
+ (MRI ruby 1.8.7 was supported up through version 1.1.1)
134
+
135
+ ## History
136
+
137
+ Release Notes
138
+
139
+ * 1.2.0 Add support for Hash comprehensions; drop support for ruby 1.8.7
140
+ * 1.1.1 Remove dependency on BlankSlate
141
+
142
+ This gem is orignally based on Jay Philips'
143
+ [methodphitamine](https://github.com/jicksta/methodphitamine) gem. It has been
144
+ updated to be compatible with ruby 1.9 and gemspec, added case statement
145
+ support, renamed its-it, and installed on [rubygems.org](http://rubygems.org).
146
+ Unlike methodphitamine, this gem includes only `its` and `it`, not the
147
+ "maybe" monad.
148
+
data/Rakefile CHANGED
@@ -1,44 +1,20 @@
1
1
  require 'rubygems'
2
-
3
- begin
4
- require 'bundler'
5
- rescue LoadError
6
- $stderr.puts "You must install bundler - run `gem install bundler`"
7
- end
8
-
9
- begin
10
- Bundler.setup
11
- rescue Bundler::BundlerError => e
12
- $stderr.puts e.message
13
- $stderr.puts "Run `bundle install` to install missing gems"
14
- exit e.status_code
15
- end
16
- require 'rake'
17
-
18
- require 'bueller'
19
- Bueller::Tasks.new
2
+ require "bundler/gem_tasks"
20
3
 
21
4
  require 'rspec/core/rake_task'
22
5
  RSpec::Core::RakeTask.new(:spec) do |spec|
23
6
  spec.rspec_opts = '-Ispec'
24
7
  end
25
8
 
26
- RSpec::Core::RakeTask.new(:rcov) do |spec|
27
- spec.rspec_opts = '-Ispec'
28
- spec.rcov = true
29
- end
30
-
31
9
  task :default => :spec
32
10
 
33
- require "rdoc/task"
34
-
11
+ require 'rdoc/task'
35
12
  Rake::RDocTask.new do |rdoc|
36
13
  version = File.exist?('VERSION') ? File.read('VERSION') : ""
37
14
 
38
15
  rdoc.main = 'README.rdoc'
39
16
  rdoc.rdoc_dir = 'rdoc'
40
- rdoc.title = "its-it #{version}"
17
+ rdoc.title = "enumerable_hashify #{version}"
41
18
  rdoc.rdoc_files.include('README*')
42
19
  rdoc.rdoc_files.include('lib/**/*.rb')
43
20
  end
44
-
@@ -23,7 +23,6 @@ for ruby 1.9 and gemspec compatibility and adding the case statement functionali
23
23
  }
24
24
  s.extra_rdoc_files = [
25
25
  "LICENSE.txt",
26
- "README.rdoc"
27
26
  ]
28
27
 
29
28
  s.required_rubygems_version = Gem::Requirement.new('>= 1.3.7')
@@ -35,10 +34,10 @@ for ruby 1.9 and gemspec compatibility and adding the case statement functionali
35
34
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
36
35
  s.require_paths = ['lib']
37
36
 
37
+ s.add_development_dependency 'rake'
38
38
  s.add_development_dependency 'rdoc'
39
- s.add_development_dependency 'rspec'
39
+ s.add_development_dependency 'rspec', "~> 3.0"
40
40
  s.add_development_dependency 'bundler'
41
- s.add_development_dependency 'bueller'
42
41
  s.add_development_dependency 'simplecov'
43
42
  s.add_development_dependency 'simplecov-gem-adapter'
44
43
 
@@ -17,20 +17,18 @@ module ItsIt
17
17
  end
18
18
 
19
19
  def initialize #:nodoc:
20
- @methods = []
20
+ @queue = []
21
21
  end
22
22
 
23
- def method_missing(*args, &block)
24
- @methods << [args, block] unless args.first == :respond_to? and [:to_proc, :===].include?(args[1].to_sym)
23
+ def method_missing(method, *args, &block)
24
+ @queue << [method, args, block] unless method == :respond_to? and [:to_proc, :===].include?(args.first.to_sym)
25
25
  self
26
26
  end
27
27
 
28
28
  def to_proc
29
- Kernel.send :lambda do |obj|
30
- ret = @methods.inject(obj) do |current,(args,block)|
31
- current.send(*args, &block)
32
- end
33
- ret
29
+ Kernel.send :proc do |*obj|
30
+ obj = obj.shift if obj.size == 1
31
+ @queue.inject(obj) { |chain,(method, args,block)| chain.send(method, *args, &block) }
34
32
  end
35
33
  end
36
34
 
@@ -1,3 +1,3 @@
1
1
  module ItsIt
2
- VERSION = "1.1.1"
2
+ VERSION = "1.2.0"
3
3
  end
@@ -1,74 +1,76 @@
1
1
  require File.dirname(__FILE__) + "/spec_helper"
2
2
 
3
- describe "An It instance" do
3
+ describe ItsIt::It do
4
4
 
5
- before (:each) do
6
- it = ItsIt::It.new
7
- @string = "This is a test"
8
- end
5
+ TestString = "This is a test"
9
6
 
10
7
  it "should start with identity via to_proc" do
11
- it.to_proc.call(@string).should == @string
8
+ expect(it.to_proc.call(TestString)).to eq(TestString)
12
9
  end
13
10
 
14
11
  it "should start with identity via ===" do
15
- (it === @string).should == @string
12
+ expect(it === TestString).to eq(TestString)
16
13
  end
17
14
 
18
15
  it "should work with a simple method via to_proc" do
19
- (it.length).to_proc.call(@string).should == @string.length
16
+ expect((it.length).to_proc.call(TestString)).to eq(TestString.length)
20
17
  end
21
18
 
22
- it "should work with a simple methoud using ===" do
23
- ((it.length) === @string).should == @string.length
19
+ it "should work with a simple method using ===" do
20
+ expect((it.length) === TestString).to eq(TestString.length)
24
21
  end
25
22
 
26
23
  it "should work with arguments" do
27
- (it.sub(/test/, 'kumquat')).call(@string).should == 'This is a kumquat'
24
+ expect((it.sub(/test/, 'kumquat')).call(TestString)).to eq('This is a kumquat')
28
25
  end
29
26
 
30
27
  it "should work with a block" do
31
- (it.sub(/test/) {"balloon"}).to_proc.call(@string).should == 'This is a balloon'
28
+ expect((it.sub(/test/) {"balloon"}).to_proc.call(TestString)).to eq('This is a balloon')
32
29
  end
33
30
 
34
31
  it "should chain methods" do
35
- it.reverse.swapcase.succ.should == "TSET A SI SIHu"
32
+ expect(it.reverse.swapcase.succ).to eq("TSET A SI SIHu")
36
33
  end
37
34
 
38
35
  it "should respond to to_proc()" do
39
- it.should respond_to(:to_proc)
36
+ expect(it).to respond_to(:to_proc)
40
37
  end
41
38
 
42
39
  it "should respond to ===" do
43
- it.should respond_to(:===)
40
+ expect(it).to respond_to(:===)
44
41
  end
45
42
 
46
43
  it "should work with numbers" do
47
- ((it < 1) === 0).should be_true
48
- ((it < 1) === 1).should be_false
49
- ((it < 1) === 2).should be_false
44
+ expect((it < 1) === 0).to be_truthy
45
+ expect((it < 1) === 1).to be_falsey
46
+ expect((it < 1) === 2).to be_falsey
47
+ end
48
+
49
+ it "should work with hashes (multiple args)" do
50
+ expect({a: 1, b:2}.select &it[1] == 2).to eq({b:2})
50
51
  end
51
52
 
53
+
52
54
  it "should work in a case statement" do
53
55
  [0,1,2].each do |i|
54
56
  case i
55
- when it < 1 then i.should == 0
56
- when it == 1 then i.should == 1
57
- else i.should == 2
57
+ when it < 1 then expect(i).to eq(0)
58
+ when it == 1 then expect(i).to eq(1)
59
+ else expect(i).to eq(2)
58
60
  end
59
61
  end
60
62
  end
61
63
 
62
64
  it "should not queue the method respond_to? when given :to_proc as an arg" do
63
- (it.respond_to? :to_proc).should be_true
65
+ expect(it.respond_to? :to_proc).to be_true
64
66
  end
65
67
 
66
68
  it "should not queue the method respond_to? when given :=== as an arg" do
67
- (it.respond_to? :===).should be_true
69
+ expect(it.respond_to? :===).to be_true
68
70
  end
69
71
 
70
72
  it "should queue the method respond_to? when given generic arg" do
71
- (it.respond_to? :size).to_proc.call(@string).should be_true
73
+ expect((it.respond_to? :size).to_proc.call(TestString)).to be_truthy
72
74
  end
73
-
75
+
74
76
  end
@@ -1,20 +1,18 @@
1
1
  require File.dirname(__FILE__) + "/spec_helper"
2
2
 
3
- describe "The ItsIt's RSpec compatibility" do
3
+ describe "RSpec compatibility" do
4
4
 
5
5
  # Surprisingly, RSpec's it() method isn't even defined within the context
6
6
  # of each expectation block. Man, that's some crazy voodoo.
7
7
 
8
8
  it "should make available the it and its methods" do
9
- should respond_to(:it)
10
- should respond_to(:its)
11
- method(:it).should == method(:its) # Ensure it's not RSpec's it() method
12
- lambda do
9
+ expect(method(:it)).to eq method(:its) # Ensure it's not RSpec's it() method
10
+ expect {
13
11
  it.should be_kind_of(ItsIt::It)
14
- end.should_not raise_error
12
+ }.to_not raise_error
15
13
  end
16
14
 
17
- it "should work with RSpec's assertion methods" do
15
+ it "should work with RSpec's old :should syntax" do
18
16
  [1,2,3].each &it.should(be_kind_of(Fixnum))
19
17
  end
20
18
  end
@@ -14,5 +14,7 @@ require 'its-it'
14
14
  Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
15
15
 
16
16
  RSpec.configure do |config|
17
-
17
+ config.expect_with(:rspec) do |c|
18
+ c.syntax = [:expect, :should]
19
+ end
18
20
  end
metadata CHANGED
@@ -1,115 +1,123 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: its-it
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
5
- prerelease:
4
+ version: 1.2.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Ronen Barzel
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2011-04-26 00:00:00.000000000Z
11
+ date: 2011-04-26 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
- name: rdoc
16
- requirement: &70172872051900 !ruby/object:Gem::Requirement
17
- none: false
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
18
16
  requirements:
19
- - - ! '>='
17
+ - - ">="
20
18
  - !ruby/object:Gem::Version
21
19
  version: '0'
22
20
  type: :development
23
21
  prerelease: false
24
- version_requirements: *70172872051900
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
25
27
  - !ruby/object:Gem::Dependency
26
- name: rspec
27
- requirement: &70172872051440 !ruby/object:Gem::Requirement
28
- none: false
28
+ name: rdoc
29
+ requirement: !ruby/object:Gem::Requirement
29
30
  requirements:
30
- - - ! '>='
31
+ - - ">="
31
32
  - !ruby/object:Gem::Version
32
33
  version: '0'
33
34
  type: :development
34
35
  prerelease: false
35
- version_requirements: *70172872051440
36
- - !ruby/object:Gem::Dependency
37
- name: bundler
38
- requirement: &70172872050980 !ruby/object:Gem::Requirement
39
- none: false
36
+ version_requirements: !ruby/object:Gem::Requirement
40
37
  requirements:
41
- - - ! '>='
38
+ - - ">="
42
39
  - !ruby/object:Gem::Version
43
40
  version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
44
48
  type: :development
45
49
  prerelease: false
46
- version_requirements: *70172872050980
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
47
55
  - !ruby/object:Gem::Dependency
48
- name: bueller
49
- requirement: &70172872044640 !ruby/object:Gem::Requirement
50
- none: false
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
51
58
  requirements:
52
- - - ! '>='
59
+ - - ">="
53
60
  - !ruby/object:Gem::Version
54
61
  version: '0'
55
62
  type: :development
56
63
  prerelease: false
57
- version_requirements: *70172872044640
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
58
69
  - !ruby/object:Gem::Dependency
59
70
  name: simplecov
60
- requirement: &70172872044220 !ruby/object:Gem::Requirement
61
- none: false
71
+ requirement: !ruby/object:Gem::Requirement
62
72
  requirements:
63
- - - ! '>='
73
+ - - ">="
64
74
  - !ruby/object:Gem::Version
65
75
  version: '0'
66
76
  type: :development
67
77
  prerelease: false
68
- version_requirements: *70172872044220
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: simplecov-gem-adapter
71
- requirement: &70172872043800 !ruby/object:Gem::Requirement
72
- none: false
85
+ requirement: !ruby/object:Gem::Requirement
73
86
  requirements:
74
- - - ! '>='
87
+ - - ">="
75
88
  - !ruby/object:Gem::Version
76
89
  version: '0'
77
90
  type: :development
78
91
  prerelease: false
79
- version_requirements: *70172872043800
80
- description: ! '
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: |2
81
98
 
82
99
  This gem defines the Kernel method "it" that queue and defer method calls.
83
-
84
100
  This extends the Symbol#to_proc idiom to support chaining multiple methods.
85
-
86
101
  For example, items.collect(&it.to_s.capitalize). This also allows
87
-
88
102
  conditionals in case statements, such as: case ... when it > 3 then [etc.].
89
-
90
103
  The method is also aliased as "its", for methods that describe possessives
91
-
92
104
  rather than actions, such as items.collect(&its.name.capitalize)
93
105
 
94
-
95
- [This gem is an extension of Jay Philips'' "methodphitamine" gem, updated
96
-
106
+ [This gem is an extension of Jay Philips' "methodphitamine" gem, updated
97
107
  for ruby 1.9 and gemspec compatibility and adding the case statement functionality.]
98
-
99
- '
100
108
  email: ronen@barzel.org
101
109
  executables: []
102
110
  extensions: []
103
111
  extra_rdoc_files:
104
112
  - LICENSE.txt
105
- - README.rdoc
106
113
  files:
107
- - .document
108
- - .gitignore
109
- - .rspec
114
+ - ".document"
115
+ - ".gitignore"
116
+ - ".rspec"
117
+ - ".travis.yml"
110
118
  - Gemfile
111
119
  - LICENSE.txt
112
- - README.rdoc
120
+ - README.md
113
121
  - Rakefile
114
122
  - its-it.gemspec
115
123
  - lib/its-it.rb
@@ -121,28 +129,24 @@ files:
121
129
  - spec/spec_helper.rb
122
130
  homepage: http://github.com/ronen/its-it
123
131
  licenses: []
132
+ metadata: {}
124
133
  post_install_message:
125
134
  rdoc_options: []
126
135
  require_paths:
127
136
  - lib
128
137
  required_ruby_version: !ruby/object:Gem::Requirement
129
- none: false
130
138
  requirements:
131
- - - ! '>='
139
+ - - ">="
132
140
  - !ruby/object:Gem::Version
133
141
  version: '0'
134
- segments:
135
- - 0
136
- hash: -4170040046291894423
137
142
  required_rubygems_version: !ruby/object:Gem::Requirement
138
- none: false
139
143
  requirements:
140
- - - ! '>='
144
+ - - ">="
141
145
  - !ruby/object:Gem::Version
142
146
  version: 1.3.7
143
147
  requirements: []
144
148
  rubyforge_project:
145
- rubygems_version: 1.8.6
149
+ rubygems_version: 2.4.5.1
146
150
  signing_key:
147
151
  specification_version: 3
148
152
  summary: Defines its() and it() method-chain proxies.
@@ -1,110 +0,0 @@
1
- = its-it
2
-
3
- == Overview
4
-
5
- This gem defines kernel methods <code>its</code> and <code>it</code> that
6
- queue and defer method calls. This is handy for list enumeration and case
7
- statements.
8
-
9
- == List Enumeration
10
-
11
- <code>its</code> and <code>it</code> extend the Symbol#to_proc idiom to
12
- support chaining multiple methods.
13
-
14
- The pure Ruby way to chain methods when enumerating a list would be:
15
-
16
- users.collect{|user| user.contact}.collect{|contact| contact.last_name}.collect{|name| name.capitalize}
17
-
18
- Using <code>Symbol#to_proc</code>, this becomes simpler:
19
-
20
- users.collect(&:contact).collect(&:last_name).collect(&:capitalize)
21
-
22
- And using <code>its</code>, this becomes becomes simpler still:
23
-
24
- users.collect(&its.contact.last_name.capitalize)
25
-
26
- Note that <code>its</code> captures arguments and blocks, allowing constructs like this,
27
- which will select users whose names include any non-hyphenated word that's more than 10
28
- letters long:
29
- users.select(&its.name.split(/ /).reject{|word| word =~ /-/}.collect(&:length).max > 10)
30
-
31
- <code>it</code> is an alias for <code>its</code>, to use with methods that
32
- describe actions rather than posessives. For example:
33
-
34
- items.collect(&it.to_s.capitalize)
35
-
36
- == Case statements
37
-
38
- <code>its</code> and <code>it</code> likewise extend Ruby's
39
- <code>code</code> statement to support testing arbitrary methods,
40
- minimizing the need to create temporary variables and use
41
- <code>if-elsif</code> constructs.
42
-
43
- In pure Ruby, doing comparisons on computed values would be done something
44
- like this:
45
-
46
- maxlen = arrays.collect(&size).max
47
- if maxlen > 10000
48
- "too big"
49
- elsif maxlen < 10
50
- "too small"
51
- else
52
- "okay"
53
- end
54
-
55
- But using <code>it</code> this becomes:
56
-
57
- case arrays.collect(&size).max
58
- when it > 1000
59
- "too big"
60
- when it < 10
61
- "too small"
62
- else
63
- "okay"
64
- end
65
-
66
- Of course method chanining can be used here too:
67
-
68
- case users.first
69
- when its.name == "Gimme Cookie" then ...
70
- when its.name.length > 10 then ...
71
- else ...
72
- end
73
-
74
- == Under the hood
75
-
76
- The <code>ItsIt::It</code> class starts from <code>BlankSlate</code>, and
77
- uses <code>method_missing</code> to capture and queue up all methods and
78
- their arguments, with the exception of <code>:to_proc</code> and <code>:===</code>
79
- (and also excepting <code>:respond_to? :to_proc</code> and
80
- <code>:respond_to? :===</code>).
81
-
82
- <code>:to_proc</code> returns a proc that will evaluate the method queue on
83
- a given argument. <code>:===</code> takes an argument and evaluates that
84
- proc, returning the result.
85
-
86
- == Installation
87
-
88
- Install from http://rubygems.org via
89
-
90
- $ gem install "its-it"
91
-
92
- or in a Gemfile
93
-
94
- gem "its-it"
95
-
96
- == Compatibility
97
-
98
- Works with MRI ruby 1.8.7, 1.9.2, 1.9.3
99
-
100
- == History
101
-
102
- This gem is orignally based on Jay Philips'
103
- methodphitamine[https://github.com/jicksta/methodphitamine] gem. It has
104
- been updated to be compatible with ruby 1.9 and gemspec, added case
105
- statement support, renamed its-it, and installed on
106
- rubygems.org[http://rubygems.org]. Unlike methodphitamine, this gem
107
- includes only <code>its</code> and <code>it</code>, not the "maybe" monad.
108
-
109
- Release Notes
110
- * 1.1.1 Remove dependency on BlankSlate