Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

first commit

  • Loading branch information...
commit 653d666dfcc00b4ab3eb389d07bb386afb172e9f 0 parents
@txus authored
3  .gitignore
@@ -0,0 +1,3 @@
+pkg/*
+*.gem
+.bundle
1  .rvmrc
@@ -0,0 +1 @@
+rvm --create use ruby-1.9.2@yo
4 Gemfile
@@ -0,0 +1,4 @@
+source "http://rubygems.org"
+
+# Specify your gem's dependencies in yo.gemspec
+gemspec
2  Rakefile
@@ -0,0 +1,2 @@
+require 'bundler'
+Bundler::GemHelper.install_tasks
74 Readme.md
@@ -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.
42 examples/person.rb
@@ -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
+
65 lib/yo.rb
@@ -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
3  lib/yo/version.rb
@@ -0,0 +1,3 @@
+module Yo
+ VERSION = "0.0.1"
+end
21 yo.gemspec
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.