Browse files

Hash.to_lolz, Array.to_lolz, kthnx.

  • Loading branch information...
1 parent fb6314e commit 3087d925a042ea2fb9af98bc2c3b6330424ac8fc @igrigorik committed Dec 12, 2009
Showing with 40 additions and 1 deletion.
  1. +19 −0 Rakefile
  2. +8 −0 lib/ruby2lolz.rb
  3. +13 −1 spec/lolz_spec.rb
View
19 Rakefile
@@ -0,0 +1,19 @@
+require 'rake'
+
+begin
+ require 'jeweler'
+ Jeweler::Tasks.new do |gemspec|
+ gemspec.name = "ruby2lolz"
+ gemspec.summary = "Ruby to Lolcode translator, kthnxbai."
+ gemspec.description = gemspec.summary
+ gemspec.email = "ilya@igvita.com"
+ gemspec.homepage = "http://github.com/igrigorik/ruby2lolz"
+ gemspec.authors = ["Ilya Grigorik"]
+ gemspec.add_dependency('ParseTree')
+ gemspec.rubyforge_project = "ruby2lolz"
+ end
+
+ Jeweler::GemcutterTasks.new
+rescue LoadError
+ puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
+end
View
8 lib/ruby2lolz.rb
@@ -6,6 +6,14 @@
require "parse_tree_extensions"
require "unified_ruby"
+class Hash
+ def to_lolz; Ruby2Lolz.translate(self.inspect); end
+end
+
+class Array
+ def to_lolz; Ruby2Lolz.translate(self.inspect); end
+end
+
class Ruby2Lolz < SexpProcessor
def self.translate(klass_or_str, method = nil)
View
14 spec/lolz_spec.rb
@@ -17,17 +17,29 @@ def read_spec(name); File.open("spec/specs/#{name}.txt", "r").read.gsub("\r", ""
h = {:user => "Ilya"}.inspect
Ruby2Lolz.translate(h).should == read_spec("hash")
end
+
+ it "should translate Ruby hash to lolz, kthnx" do
+ {:user => "Ilya"}.to_lolz.should == read_spec("hash")
+ end
it "should translate Ruby array to lolz, kthnx" do
a = ["igrigorik", "ig"].inspect
Ruby2Lolz.translate(a).should == read_spec("array")
end
+
+ it "should translate Ruby array to lolz, kthnx" do
+ ["igrigorik", "ig"].to_lolz.should == read_spec("array")
+ end
it "should translate mixed Ruby array/hash to lolz, kthnx" do
h = {:nickname => ["igrigorik", "ig"]}.inspect
Ruby2Lolz.translate(h).should == read_spec("hash_array")
end
-
+
+ it "should translate mixed Ruby array/hash to lolz, kthnx" do
+ {:nickname => ["igrigorik", "ig"]}.to_lolz.should == read_spec("hash_array")
+ end
+
it "should translate Ruby method to lolz, kthnx" do
# [:defn,
# :hello,

0 comments on commit 3087d92

Please sign in to comment.