condition_red 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: cdfa3ad0b77c0a883dd060797ec1913f8a680285
4
+ data.tar.gz: 4f32f463f92847778fd8adba7212543934f4bf83
5
+ SHA512:
6
+ metadata.gz: 6c935e65a3be74f0b2837376e932d66f9bb6515e13ae7fc31a30e45cd0d1113b1e237632f4fb4e2c8fbae9245f969f938177782737affe97148de09c61c9d678
7
+ data.tar.gz: cee401ae69032629f04e3e678422ce39fb43a8cdc973522168353cb180e67c44b58e7d4983c84d339df873b517999ec4cb171513263db2c595cd7e27b0e4576f
@@ -0,0 +1,45 @@
1
+ require 'condition_red/truthiness'
2
+ require 'bundler'
3
+ Bundler.require
4
+
5
+ module ConditionRed
6
+ end
7
+
8
+ class TrueClass
9
+ include ConditionRed::Truthy
10
+ end
11
+
12
+ class FalseClass
13
+ include ConditionRed::Falsey
14
+ end
15
+
16
+ class NilClass
17
+ include ConditionRed::Falsey
18
+ def if_nil &block
19
+ yield
20
+ end
21
+ end
22
+
23
+ class Object
24
+ include ConditionRed::Truthy
25
+ def if conditions={}
26
+ conditions = {true: ->{}, false: ->{}, nil: ->{}}.merge conditions
27
+ if_true(&conditions[:true]).or{if_false &conditions[:false]}.or{if_nil &conditions[:nil]}
28
+ end
29
+ def case cases={}
30
+ any_case = false
31
+ result = nil
32
+ cases.each_pair do |key, value|
33
+ (key==self).if true: -> do
34
+ any_case = true
35
+ result = value.respond_to?(:call).if true: ->{value.call}, false: ->{value}
36
+ end
37
+ end
38
+ any_case.if false: ->{
39
+ cases[:else].nil?.if false: -> do
40
+ result = cases[:else].respond_to?(:call).if true: ->{cases[:else].call}, false: ->{cases[:else]}
41
+ end
42
+ }
43
+ result
44
+ end
45
+ end
@@ -0,0 +1,39 @@
1
+ module ConditionRed
2
+ module Truthy
3
+ def this
4
+ self
5
+ end
6
+ def if_true &block
7
+ yield
8
+ end
9
+ def if_false &block
10
+ end
11
+ def if_nil &block
12
+ end
13
+ def and &block
14
+ yield
15
+ end
16
+ def or &block
17
+ self
18
+ end
19
+ end
20
+
21
+ module Falsey
22
+ def this
23
+ self
24
+ end
25
+ def if_true &block
26
+ end
27
+ def if_false &block
28
+ yield
29
+ end
30
+ def if_nil &block
31
+ end
32
+ def and &block
33
+ self
34
+ end
35
+ def or &block
36
+ yield
37
+ end
38
+ end
39
+ end
metadata ADDED
@@ -0,0 +1,46 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: condition_red
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Ben Titcomb
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-02-24 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Adds conditional methods similar to those in Smalltalk.
14
+ email: benjamin@pixelstreetinc.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - lib/condition_red.rb
20
+ - lib/condition_red/truthiness.rb
21
+ homepage: http://github.com/ravenstine/condition-red
22
+ licenses:
23
+ - MIT
24
+ metadata: {}
25
+ post_install_message:
26
+ rdoc_options: []
27
+ require_paths:
28
+ - lib
29
+ required_ruby_version: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ required_rubygems_version: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - ">="
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ requirements: []
40
+ rubyforge_project:
41
+ rubygems_version: 2.4.5
42
+ signing_key:
43
+ specification_version: 4
44
+ summary: Adds conditional methods similar to those in Smalltalk.
45
+ test_files: []
46
+ has_rdoc: