Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Josep M. Bach
committed
Jan 13, 2011
0 parents
commit 653d666
Showing
9 changed files
with
215 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
pkg/* | ||
*.gem | ||
.bundle |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
rvm --create use ruby-1.9.2@yo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
source "http://rubygems.org" | ||
|
||
# Specify your gem's dependencies in yo.gemspec | ||
gemspec |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
require 'bundler' | ||
Bundler::GemHelper.install_tasks |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
#yo: Street-oriented programming in Ruby | ||
|
||
Shake those classes baby! Have you ever felt like bored after you wrote a | ||
snippet like this? | ||
|
||
class Person | ||
attr_accessor :name, :age, :mood, :money | ||
end | ||
|
||
Just `gem install yo` or put `gem 'yo'` in your Gemfile, put your badass face | ||
and type this: | ||
|
||
require 'yo' | ||
|
||
class Person | ||
extend Yo | ||
|
||
so i think it goes like this | ||
|
||
defnly he shud have an accessor 'name' | ||
a person also has a property 'age', yeah | ||
|
||
ya should know he has some freakin 'money', too | ||
prolly he demands some privacy on da 'money', yo | ||
|
||
he might as well have a pretty badass 'mood' | ||
but you never know inthis neighborhood | ||
|
||
but hey maybe its all bullshit, so | ||
we better get going bro | ||
|
||
shake it baby, yeah | ||
|
||
end | ||
|
||
You can check it's all flawlessly working: | ||
|
||
john = Person.new | ||
john.name = "John" | ||
john.name # => "John" | ||
|
||
john.age = 29 | ||
john.age # => 29 | ||
|
||
john.money = "$3" | ||
john.money # => "$3" | ||
|
||
john.mood = :badass | ||
john.mood # => :badass | ||
|
||
Now that's some street-oriented programming! | ||
|
||
##Install | ||
|
||
gem install yo | ||
|
||
... or if you use Bundler: | ||
|
||
gem 'yo' | ||
|
||
##Contribute! | ||
|
||
* Fork the project. | ||
* Make your feature addition or bug fix. | ||
* Add specs for it. This is important so I don't break it in a future | ||
version unintentionally. | ||
* Commit, do not mess with rakefile, version, or history. | ||
If you want to have your own version, that is fine but bump version | ||
in a commit by itself I can ignore when I pull. | ||
* Send me a pull request. Bonus points for topic branches. | ||
|
||
## Copyright | ||
|
||
Copyright (c) 2011 Josep M. Bach. See LICENSE for details. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
require_relative '../lib/yo' | ||
|
||
class Person | ||
extend Yo | ||
|
||
so i think it goes like this | ||
|
||
defnly he shud have an accessor 'name' | ||
a person also has a property 'age', yeah | ||
|
||
ya should know he has some freakin 'money', too | ||
prolly he demands some privacy on da 'money', yo | ||
|
||
he might as well have a pretty badass 'mood' | ||
but you never know inthis neighborhood | ||
|
||
but hey maybe its all bullshit, so | ||
we better get going bro | ||
|
||
shake it baby, yeah | ||
|
||
end | ||
|
||
# The same as: | ||
# | ||
# class Person | ||
# attr_accessor :name, :age, :mood, :money | ||
# end | ||
|
||
john = Person.new | ||
john.name = "John" | ||
puts john.name # => "John" | ||
|
||
john.age = 29 | ||
puts john.age # => 29 | ||
|
||
john.money = "$3" | ||
puts john.money # => "$3" | ||
|
||
john.mood = :badass | ||
puts john.mood # => :badass | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
module Yo | ||
|
||
def method_missing(method, *args) | ||
process_metainf_from(method, *args) | ||
do_what_you_have_to | ||
nil | ||
end | ||
|
||
private | ||
|
||
def process_metainf_from(method, *args) | ||
if value = args.detect {|a| String === a} | ||
@__value = value | ||
end | ||
|
||
case method | ||
when :it then {} | ||
when :has, :have | ||
@__have = true | ||
if args.detect {|a| a == :not } | ||
@__negative = true | ||
end | ||
when :maybe, :might, :may | ||
@__maybe = true | ||
when :accessor, :property | ||
@__have_what = :accessor | ||
when :reader, :getter | ||
@__have_what = :reader | ||
when :writer, :setter | ||
@__have_what = :writer | ||
when :privacy | ||
@__set_private_method = true | ||
end | ||
end | ||
|
||
def do_what_you_have_to | ||
if @__have && !@__negative | ||
string = case @__have_what | ||
when :reader | ||
string = """ | ||
def #{@__value} | ||
@#{@__value} | ||
end | ||
""" | ||
when :writer | ||
string = """ | ||
def #{@__value}=(value) | ||
@#{@__value} = value | ||
end | ||
""" | ||
when :accessor, nil | ||
string = """ | ||
def #{@__value} | ||
@#{@__value} | ||
end | ||
def #{@__value}=(value) | ||
@#{@__value} = value | ||
end | ||
""" | ||
end | ||
class_eval string | ||
end | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module Yo | ||
VERSION = "0.0.1" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# -*- encoding: utf-8 -*- | ||
$:.push File.expand_path("../lib", __FILE__) | ||
require "yo/version" | ||
|
||
Gem::Specification.new do |s| | ||
s.name = "yo" | ||
s.version = Yo::VERSION | ||
s.platform = Gem::Platform::RUBY | ||
s.authors = ["Josep M. Bach"] | ||
s.email = ["josep.m.bach@gmail.com"] | ||
s.homepage = "http://github.com/txus/yo" | ||
s.summary = %q{Street-oriented programming in Ruby} | ||
s.description = %q{Street-oriented programming in Ruby} | ||
|
||
s.rubyforge_project = "yo" | ||
|
||
s.files = `git ls-files`.split("\n") | ||
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n") | ||
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) } | ||
s.require_paths = ["lib"] | ||
end |