Permalink
Browse files

added more flexibility to -m option in rubyjs

  • Loading branch information...
superchris committed Jun 8, 2008
1 parent 7b305b4 commit 0ec8f7f3cede75c53e977af40cc58cf201a4b7af
Showing with 18 additions and 4 deletions.
  1. +5 −1 bin/rubyjs
  2. +2 −2 examples/hangman/hangman.rb
  3. +6 −0 src/rubyjs/lib/core.rb
  4. +5 −1 test/test_array.rb
View
@@ -127,7 +127,11 @@ end
gen = CodeGenerator.new
str = ""
str << gen.generate()
-str << gen.encode("function main() { return #<#{options.main}>.#<m:main>.apply(#<#{options.main}>, arguments); }") if options.main
+if options.main
+ klass, method = options.main.split(".")
+ method ||= "main"
+ str << gen.encode("#<#{klass}>.#<m:#{method}>.apply(#<#{klass}>); ")
+end
str << options.append
options.outputs.each do |outname|
@@ -96,6 +96,7 @@ def display_word
def guess(letter)
if letters.include?(letter)
@guessed_letters[letter] = true
+ @letters_div.inner_html = display_word
puts "You win!" if won?
else
@misses += 1
@@ -105,7 +106,6 @@ def guess(letter)
@guess_button["disabled"] = true
end
end
- @letters_div.inner_html = display_word
@guess_input["value"] = ""
end
@@ -117,7 +117,7 @@ def won?
@guessed_letters.values.each do |guessed|
return false unless guessed
end
- return
+ return true
end
def self.main
View
@@ -805,6 +805,12 @@ def eql?(other)
end
end
+ def include?(candidate)
+ each do |elem|
+ return true if elem.eql?(candidate)
+ end
+ false
+ end
end
class Regexp
View
@@ -13,5 +13,9 @@ def test_delete
assert_equal a, ["a", "c"]
end
-
+ def test_include
+ assert [1, 2, 3].include? 2
+ assert ! [1, 3].include?(2)
+ end
+
end

0 comments on commit 0ec8f7f

Please sign in to comment.