Skip to content

Instantly share code, notes, and snippets.

@ptn
Forked from jacksonwillis/s.rb
Created April 11, 2012 14:19
Show Gist options
  • Save ptn/2359584 to your computer and use it in GitHub Desktop.
Save ptn/2359584 to your computer and use it in GitHub Desktop.
Sentences as Ruby code
class S; def initialize *w; @s=w; end; def method_missing *w;@s<<w;self;end;def
to_ary;[@s.map{ |e| e=~/[\,\.\:\-\(\)\/\'\"]/?[e]:[" ",e] }.join.strip];end;end
def Object.const_missing(c);S.new c;end; ###### https://gist.github.com/2354740
puts This.is.a.sentence.represented.by.a.Ruby.expression(",").try.it.out! #####
#!/usr/bin/env ruby
# https://gist.github.com/2354740
class Sentence
def initialize(*words)
@sentence = words.flatten
end
def method_missing(*words)
@sentence += words.flatten
self
end
def to_ary
[@sentence.map { |el| el =~ /[\,\.\:\-\(\)\/\'\"]/ ? [el] : [" ", el] }.join.strip]
end
end
def Object.const_missing(const)
Sentence.new const
end
puts One.small.step.for.a.man(",").a.giant.leap.for.mankind!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment