-
-
Save ptn/2359584 to your computer and use it in GitHub Desktop.
Sentences as Ruby code
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
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! ##### |
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
#!/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