Skip to content

Instantly share code, notes, and snippets.

@pratul
Forked from kitallis/pratulkalia.rb
Created December 14, 2010 18:15

Revisions

  1. @kitallis kitallis created this gist Dec 14, 2010.
    78 changes: 78 additions & 0 deletions pratulkalia.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,78 @@
    class PratulKalia
    class << self
    def should(&sblk)
    self.new.instance_eval(&sblk)
    end
    end
    end

    class Blabber
    def things(arg)
    puts "Pratul Kalia should fucken stop blabbering about things like: #{arg.join(", ")}"
    end

    def like(*arg)
    arg
    end
    end


    class Calculate
    def initialize
    ["expression", "statement", "problem"].map {|m|
    class << self
    self
    end.send(:define_method, m) {|arg|
    puts "Pratul Kalia thinks that #{arg}is #{eval arg}"
    }
    }
    end

    def method_missing(meth, arg = nil, &block)
    "#{value(meth)} #{arg}"
    end

    def value(number)
    {:one => 1, :two => 2, :three => 3, :four => 4, :five => 5, :six => 6, :seven => 7,
    :eight => 8, :nine => 9, :zero => 0}.fetch(number)
    end

    def times(args)
    "* #{args}"
    end

    def by(args)
    "/ #{args}"
    end

    def from(args)
    "- #{args}"
    end

    def with(args)
    "+ #{args}"
    end

    end

    class Symbol
    def this(&sblk)
    if self == :calculate
    Calculate.new.instance_eval(&sblk)
    end
    if self == :print
    puts "Pratul Kalia says #{yield}"
    end
    end

    def about(&blk)
    if self == :shutup
    Blabber.new.instance_eval(&blk)
    end
    end
    end

    PratulKalia.should {
    :print.this { "I AM AWESOME" } & :calculate.this { expression four times three with two } & :shutup.about { things like "FONTS", "OS X", "Sneha" }\
    & :calculate.this { statement eight by four with three }
    }