Skip to content

Commit

Permalink
First release
Browse files Browse the repository at this point in the history
  • Loading branch information
chancancode committed Sep 25, 2013
0 parents commit 0bc7b2d
Show file tree
Hide file tree
Showing 11 changed files with 203 additions and 0 deletions.
17 changes: 17 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
*.gem
*.rbc
.bundle
.config
.yardoc
Gemfile.lock
InstalledFiles
_yardoc
coverage
doc/
lib/bundler/man
pkg
rdoc
spec/reports
test/tmp
test/version_tmp
tmp
6 changes: 6 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
source 'https://rubygems.org'

# Specify your gem's dependencies in canada.gemspec
gemspec

gem 'minitest'
22 changes: 22 additions & 0 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
Copyright (c) 2013 Godfrey Chan

MIT License

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
50 changes: 50 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Canada

![Canadian flag](https://raw.github.com/vanruby/canada/master/canada.png)

It's well known that we have [different conventions](http://programmers.stackexchange.com/questions/1483/do-people-in-non-english-speaking-countries-code-in-english#answer-5576) for programming in Canada. This gem attempts to make life easier for Canadian Rubyists by integrating these conventions into the Ruby language:

```ruby
>> require 'canada'
=> true
>> [].empty_eh?
=> true
>> [1,2,3].empty_eh?
=> false
>> [].respond_to_eh?(:empty_eh?)
=> true
>> aboot Object.new
=> "#<Object:0x007f802b8b92c0>"
```

Cool, eh?

## Production Ready™, eh?

Yes.

## What about performacne?

We tuned the gem's performacne so that it's inline with everything else in Canada.

## Installation

Add this line to your application's Gemfile:

gem 'canada'

And then execute:

$ bundle

Or install it yourself as:

$ gem install canada

## Contributing

1. Fork it
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Add some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create new Pull Request
12 changes: 12 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
require 'rake'
require 'rake/testtask'
require 'bundler/gem_tasks'

task :default => :test

desc 'Run all tests'
Rake::TestTask.new do |t|
t.libs << 'test'
t.test_files = FileList['test/**/*_test.rb']
t.verbose = true
end
23 changes: 23 additions & 0 deletions canada.gemspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# coding: utf-8
lib = File.expand_path('../lib', __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'canada/version'

Gem::Specification.new do |spec|
spec.name = "canada"
spec.version = Canada::VERSION
spec.authors = ["Godfrey Chan"]
spec.email = ["[email protected]"]
spec.description = %q{Adds support for Canadian programming conventions to the Ruby language}
spec.summary = %q{[1,2,3].empty_eh? # => false}
spec.homepage = "https://github.com/vanruby/canada"
spec.license = "MIT"

spec.files = `git ls-files`.split($/)
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
spec.require_paths = ["lib"]

spec.add_development_dependency "bundler", "~> 1.3"
spec.add_development_dependency "rake"
end
Binary file added canada.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
27 changes: 27 additions & 0 deletions lib/canada.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
require "canada/version"

class Object
EH_METHOD_REGEXP = /\A(?<method_name>.+)_eh\?\z/

def respond_to?(meth, include_private = false)
if (m = EH_METHOD_REGEXP.match(meth))
super || super("#{m[:method_name]}?", include_private)
else
super
end
end

def method_missing(meth, *args, &block)
if (m = EH_METHOD_REGEXP.match(meth))
self.public_send("#{m[:method_name]}?", *args, &block)
else
super
end
end
end

module Kernel
def aboot(obj)
obj.inspect
end
end
3 changes: 3 additions & 0 deletions lib/canada/version.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module Canada
VERSION = "0.0.1"
end
40 changes: 40 additions & 0 deletions test/canada_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
require 'minitest_helper'
require 'canada'

class CanadaTest < MiniTest::Test
def test_eh?
assert [].empty_eh?
refute [1,2,3].empty_eh?
end

def test_respond_to_eh?
yes = [:empty?, :empty_eh?, :respond_to?, :respond_to_eh?]
no = [:not_there, :not_there?, :not_there_eh, :not_there_eh?]

yes.each { |y| assert([].respond_to_eh?(y), "Array should respond_to_eh? #{y}") }
no.each { |n| refute([].respond_to_eh?(n), "Array should not respond_to_eh? #{n}") }
end

def test_respond_to?
yes = [:empty?, :empty_eh?, :respond_to?, :respond_to_eh?]
no = [:not_there, :not_there?, :not_there_eh, :not_there_eh?]

yes.each { |y| assert([].respond_to?(y), "Array should respond_to_eh? #{y}") }
no.each { |n| refute([].respond_to?(n), "Array should not respond_to_eh? #{n}") }
end

def test_aboot
cases = [
[],
[1,2,3],
{},
{a: 1, b: 2},
Object.new,
true,
false,
nil
]

cases.each { |c| assert_equal c.inspect, aboot(c) }
end
end
3 changes: 3 additions & 0 deletions test/minitest_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
require 'minitest/autorun'

$:.unshift File.expand_path("../../lib", __FILE__)

0 comments on commit 0bc7b2d

Please sign in to comment.