interrogate 0.0.1

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/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.8.7
4
+ - 1.9.2
5
+ - 1.9.3
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source "http://rubygems.org"
2
+ gemspec
data/README.md ADDED
@@ -0,0 +1,19 @@
1
+ # Interrogate [![Build Status](https://secure.travis-ci.org/mhgbrown/interrogate.png)](http://travis-ci.org/mhgbrown/interrogate)
2
+ Interrogate attempts to bring Scheme-like class predication to Ruby. It provides an alternate syntax using `Module#===`.
3
+
4
+ >> String?("Hello")
5
+ >> trues
6
+ >> Symbol?(:World)
7
+ >> true
8
+ >> Float?(1.0)
9
+ >> true
10
+
11
+ You can "interrogate" multiple objects as well:
12
+
13
+ >> String?("Hello", :World, 1.0)
14
+ >> false
15
+ >> String?("Hello", "World", "1.0")
16
+ >> true
17
+
18
+ ## Feedback
19
+ Use that Github [issue tracker](https://github.com/mhgbrown/interrogate/issues)!
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ desc "Run all examples"
5
+ RSpec::Core::RakeTask.new(:spec)
6
+
7
+ task :default => :spec
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "interrogate/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "interrogate"
7
+ s.version = Interrogate::VERSION
8
+ s.authors = ["Morgan Brown"]
9
+ s.email = ["brown.mhg@gmail.com"]
10
+ s.homepage = "https://github.com/mhgbrown/interrogate"
11
+ s.summary = "Scheme-like class predication for Ruby"
12
+ s.description = "String?(\"Hello\") Interrogate attempts to bring Scheme-like class predication to Ruby. It provides an alternate syntax using Module#==="
13
+
14
+ s.rubyforge_project = "interrogate"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ s.add_dependency "rake"
22
+ s.add_development_dependency "rspec"
23
+ end
@@ -0,0 +1,46 @@
1
+ require "interrogate/version"
2
+
3
+ # String?("Hello")
4
+ # Interrogate attempts to bring Scheme-like class predication to Ruby.
5
+ # It provides an alternate syntax using Module#===
6
+ module Interrogate
7
+
8
+ # Given an interrogatory method name and arguments,
9
+ # determine which class we are asking about and
10
+ # ask each arg if it is an instance of this class.
11
+ def self.interrogate(meth, *args)
12
+ raise ArgumentError, "#{meth}: wrong number of arguments (#{args.length} for 1)" if args.length < 1
13
+ klass_name = meth.to_s.tr("?", "")
14
+ klass = Object.const_get(klass_name)
15
+ args.inject(true){|bool, obj| bool && klass === obj}
16
+ end
17
+
18
+ end
19
+
20
+ class Object
21
+
22
+ # If the method name is interrogatory, then
23
+ # try to interrogate the arguments in question.
24
+ # Otherwise, perform the default method missing
25
+ # behavior.
26
+ def self.method_missing(meth, *args, &block)
27
+ if /^[A-Z].*\?$/ === meth.to_s
28
+ Interrogate.interrogate(meth, *args)
29
+ else
30
+ super
31
+ end
32
+ end
33
+
34
+ # If the method name is interrogatory, then
35
+ # try to interrogate the arguments in question.
36
+ # Otherwise, perform the default method missing
37
+ # behavior.
38
+ def method_missing(meth, *args, &block)
39
+ if /^[A-Z].*\?$/ === meth.to_s
40
+ Interrogate.interrogate(meth, *args)
41
+ else
42
+ super
43
+ end
44
+ end
45
+
46
+ end
@@ -0,0 +1,3 @@
1
+ module Interrogate
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,18 @@
1
+ require 'spec_helper'
2
+
3
+ describe Interrogate do
4
+
5
+ it "should allow \"class interrogation\"" do
6
+ String?("Hello").should == true
7
+ end
8
+
9
+ it "should allow \"class interrogation\" of multiple things" do
10
+ String?("Hello", :World, 1.0).should == false
11
+ String?("Hello", "World", "1.0").should == true
12
+ end
13
+
14
+ it "should raise an error when there are are no arguments provided" do
15
+ lambda { String?() }.should raise_error(ArgumentError)
16
+ end
17
+
18
+ end
@@ -0,0 +1,9 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+
4
+ $:.unshift(File.dirname(__FILE__) + '/../lib')
5
+ require 'interrogate'
6
+
7
+ RSpec.configure do |config|
8
+ # n/a
9
+ end
metadata ADDED
@@ -0,0 +1,103 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: interrogate
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Morgan Brown
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2012-01-15 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: rake
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ hash: 3
29
+ segments:
30
+ - 0
31
+ version: "0"
32
+ type: :runtime
33
+ version_requirements: *id001
34
+ - !ruby/object:Gem::Dependency
35
+ name: rspec
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ none: false
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ hash: 3
43
+ segments:
44
+ - 0
45
+ version: "0"
46
+ type: :development
47
+ version_requirements: *id002
48
+ description: String?("Hello") Interrogate attempts to bring Scheme-like class predication to Ruby. It provides an alternate syntax using Module#===
49
+ email:
50
+ - brown.mhg@gmail.com
51
+ executables: []
52
+
53
+ extensions: []
54
+
55
+ extra_rdoc_files: []
56
+
57
+ files:
58
+ - .gitignore
59
+ - .travis.yml
60
+ - Gemfile
61
+ - README.md
62
+ - Rakefile
63
+ - interrogate.gemspec
64
+ - lib/interrogate.rb
65
+ - lib/interrogate/version.rb
66
+ - spec/interrogate/interrogate_spec.rb
67
+ - spec/spec_helper.rb
68
+ homepage: https://github.com/mhgbrown/interrogate
69
+ licenses: []
70
+
71
+ post_install_message:
72
+ rdoc_options: []
73
+
74
+ require_paths:
75
+ - lib
76
+ required_ruby_version: !ruby/object:Gem::Requirement
77
+ none: false
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ hash: 3
82
+ segments:
83
+ - 0
84
+ version: "0"
85
+ required_rubygems_version: !ruby/object:Gem::Requirement
86
+ none: false
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ hash: 3
91
+ segments:
92
+ - 0
93
+ version: "0"
94
+ requirements: []
95
+
96
+ rubyforge_project: interrogate
97
+ rubygems_version: 1.8.11
98
+ signing_key:
99
+ specification_version: 3
100
+ summary: Scheme-like class predication for Ruby
101
+ test_files:
102
+ - spec/interrogate/interrogate_spec.rb
103
+ - spec/spec_helper.rb