wideopenspaces-wicked 0.1.3
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.
- data/VERSION.yml +4 -0
- data/lib/wicked.rb +99 -0
- data/test/test_helper.rb +10 -0
- data/test/wicked_test.rb +7 -0
- metadata +65 -0
data/VERSION.yml
ADDED
data/lib/wicked.rb
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
$:.unshift File.dirname(__FILE__)
|
|
2
|
+
|
|
3
|
+
gem 'andand'
|
|
4
|
+
require 'andand'
|
|
5
|
+
|
|
6
|
+
module Wicked
|
|
7
|
+
# Got it? Wicked Good!
|
|
8
|
+
module Good
|
|
9
|
+
|
|
10
|
+
# Aliases for 'andand'
|
|
11
|
+
# if phone = user.et.number; .... ; end
|
|
12
|
+
alias_method :et, :andand # Latin for 'and'
|
|
13
|
+
|
|
14
|
+
# if phone = user.ask.number ....
|
|
15
|
+
alias_method :ask, :andand
|
|
16
|
+
|
|
17
|
+
# Alias for andand that's meaningful when checking booleans;
|
|
18
|
+
# this is the positive version of aint.
|
|
19
|
+
# "don't fix it" unless it.is.broken?
|
|
20
|
+
# Returns nil if 'it' is broken, so this is safer than:
|
|
21
|
+
# "don't fix it" unless it.broken?
|
|
22
|
+
alias_method :is, :andand
|
|
23
|
+
|
|
24
|
+
# Guarded method negation in the style of andand
|
|
25
|
+
# Returns the logical opposite of the method invoked on the receiver
|
|
26
|
+
# receiver.aint.method
|
|
27
|
+
# Traps NoMethodError and returns nil if receiver is nil
|
|
28
|
+
# or the method does not exist on the receiver.
|
|
29
|
+
#
|
|
30
|
+
# [].aint.empty?
|
|
31
|
+
# => false
|
|
32
|
+
# [].aint.nil?
|
|
33
|
+
# => true
|
|
34
|
+
# it.aint.broken?
|
|
35
|
+
# => false
|
|
36
|
+
#
|
|
37
|
+
# Don't be a doofus, use this wisely, on boolean methods only
|
|
38
|
+
# if you know what's good for you.
|
|
39
|
+
|
|
40
|
+
def aint (p = nil)
|
|
41
|
+
NotReturningMe.new(self)
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
# A few stylistic variations on aint
|
|
45
|
+
alias_method :isnt, :aint
|
|
46
|
+
alias_method :is_not, :aint
|
|
47
|
+
alias_method :notnot, :aint
|
|
48
|
+
|
|
49
|
+
# Hehe
|
|
50
|
+
alias_method :aintnot, :andand
|
|
51
|
+
# As in 'User, eh? Wot's yer number?'
|
|
52
|
+
# if phone = user.eh?.number; .... ; end
|
|
53
|
+
alias_method :eh?, :andand
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
class Object
|
|
59
|
+
include Wicked::Good
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
unless Module.constants.include?('BlankSlate')
|
|
63
|
+
if Module.constants.include?('BasicObject')
|
|
64
|
+
module Wicked
|
|
65
|
+
class BlankSlate < BasicObject
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
else
|
|
69
|
+
module Wicked
|
|
70
|
+
class BlankSlate
|
|
71
|
+
def self.wipe
|
|
72
|
+
instance_methods.reject { |m| m =~ /^__/ }.each { |m| undef_method m }
|
|
73
|
+
end
|
|
74
|
+
def initialize
|
|
75
|
+
BlankSlate.wipe
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
module Wicked
|
|
83
|
+
|
|
84
|
+
# A proxy that returns the opposite of whatever you ask it.
|
|
85
|
+
class NotReturningMe < BlankSlate
|
|
86
|
+
def initialize(me)
|
|
87
|
+
super()
|
|
88
|
+
@me = me
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
def method_missing(sym, *args, &block)
|
|
92
|
+
begin
|
|
93
|
+
!@me.__send__(sym, *args, &block)
|
|
94
|
+
rescue NoMethodError
|
|
95
|
+
nil
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
end
|
data/test/test_helper.rb
ADDED
data/test/wicked_test.rb
ADDED
metadata
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: wideopenspaces-wicked
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.3
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Jacob Stetser
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
|
|
12
|
+
date: 2009-01-31 00:00:00 -08:00
|
|
13
|
+
default_executable:
|
|
14
|
+
dependencies:
|
|
15
|
+
- !ruby/object:Gem::Dependency
|
|
16
|
+
name: andand
|
|
17
|
+
version_requirement:
|
|
18
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
19
|
+
requirements:
|
|
20
|
+
- - ">="
|
|
21
|
+
- !ruby/object:Gem::Version
|
|
22
|
+
version: 1.3.1
|
|
23
|
+
version:
|
|
24
|
+
description: "Wicked Good extensions to Object in the vein of #andand"
|
|
25
|
+
email: jake@wideopenspac.es
|
|
26
|
+
executables: []
|
|
27
|
+
|
|
28
|
+
extensions: []
|
|
29
|
+
|
|
30
|
+
extra_rdoc_files: []
|
|
31
|
+
|
|
32
|
+
files:
|
|
33
|
+
- VERSION.yml
|
|
34
|
+
- lib/wicked.rb
|
|
35
|
+
- test/test_helper.rb
|
|
36
|
+
- test/wicked_test.rb
|
|
37
|
+
has_rdoc: true
|
|
38
|
+
homepage: http://github.com/wideopenspaces/wicked
|
|
39
|
+
post_install_message:
|
|
40
|
+
rdoc_options:
|
|
41
|
+
- --inline-source
|
|
42
|
+
- --charset=UTF-8
|
|
43
|
+
require_paths:
|
|
44
|
+
- lib
|
|
45
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
46
|
+
requirements:
|
|
47
|
+
- - ">="
|
|
48
|
+
- !ruby/object:Gem::Version
|
|
49
|
+
version: "0"
|
|
50
|
+
version:
|
|
51
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
52
|
+
requirements:
|
|
53
|
+
- - ">="
|
|
54
|
+
- !ruby/object:Gem::Version
|
|
55
|
+
version: "0"
|
|
56
|
+
version:
|
|
57
|
+
requirements: []
|
|
58
|
+
|
|
59
|
+
rubyforge_project:
|
|
60
|
+
rubygems_version: 1.2.0
|
|
61
|
+
signing_key:
|
|
62
|
+
specification_version: 2
|
|
63
|
+
summary: "Wicked Good extensions to Object in the vein of #andand"
|
|
64
|
+
test_files: []
|
|
65
|
+
|