Skip to content

Instantly share code, notes, and snippets.

@woodie
Created August 22, 2010 05:41
Show Gist options
  • Save woodie/543374 to your computer and use it in GitHub Desktop.
Save woodie/543374 to your computer and use it in GitHub Desktop.
A challenge from Lady Java
import java.util.ArrayList
import java.util.List
class Voulez
def initialize(more:List)
@words = ArrayList.new [:want]
more.each {|s| @words.add s}
end
def self.vous(verb:String)
self.new [:you, verb]
end
def avec(noun:String) returns :void
[:with, noun, "\n\n"].each {|s| @words.add s}
@words.each {|s| print "#{s} "}
end
end
marier = "to marry"; moi = "me"
Voulez.vous(marier).avec moi

A challenge from Lady Java shown here via the JavaZone video.

Updated the message slightly, because Mirah is for the next generation of programmers.

$ mirah -e '
import java.util.ArrayList
import java.util.List

class Voulez
  def initialize(more:List)
    @words = ArrayList.new [:want]
    more.each {|s| @words.add s}
  end
  def self.vous(verb:String)
    self.new [:you, verb]
  end
  def avec(noun:String) returns :void
    [:with, noun, "\n\n"].each {|s| @words.add s}
    @words.each {|s| print "#{s} "}
  end
end
marier = "to marry"; moi = "me"

Voulez.vous(marier).avec moi
'
want you to marry with me 
// Generated from challenge.mirah
public class Challenge extends java.lang.Object {
public static void main(java.lang.String[] argv) {
java.lang.String marier = "to marry";
java.lang.String moi = "me";
Voulez.vous(marier).avec(moi);
}
}
// Generated from challenge.mirah
public class Voulez extends java.lang.Object {
private java.util.ArrayList words;
public Voulez(java.util.List more) {
this.words = new java.util.ArrayList(java.util.Collections.unmodifiableList(java.util.Arrays.asList("want")));
java.util.Iterator __xform_tmp_1 = more.iterator();
label1:
while (__xform_tmp_1.hasNext()) {
java.lang.Object s = __xform_tmp_1.next();
label2:
{
this.words.add(s);
}
}
}
public static Voulez vous(java.lang.String verb) {
return new this(java.util.Collections.unmodifiableList(java.util.Arrays.asList("you", verb)));
}
public void avec(java.lang.String noun) {
java.util.Iterator __xform_tmp_2 = java.util.Collections.unmodifiableList(java.util.Arrays.asList("with", noun, "\n\n")).iterator();
label1:
while (__xform_tmp_2.hasNext()) {
java.lang.Object s = __xform_tmp_2.next();
label2:
{
this.words.add(s);
}
}
java.util.Iterator __xform_tmp_3 = this.words.iterator();
label3:
while (__xform_tmp_3.hasNext()) {
s = __xform_tmp_3.next();
label4:
{
java.io.PrintStream temp$5 = java.lang.System.out;
temp$5.print("" + s + " ");
}
}
}
}
@Serabe
Copy link

Serabe commented Aug 22, 2010

It is avec, not avac.

@woodie
Copy link
Author

woodie commented Aug 22, 2010

good call, fixed!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment