Skip to content
This repository has been archived by the owner on Aug 18, 2018. It is now read-only.

Commit

Permalink
Added String.prototype.symbolize()
Browse files Browse the repository at this point in the history
  • Loading branch information
jbarnette committed Apr 26, 2008
1 parent b05fc61 commit bdc27a9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
6 changes: 6 additions & 0 deletions js/johnson/prelude.js
Expand Up @@ -23,6 +23,12 @@ Johnson.symbolize = function(string) {
return Johnson.symbolCache[string];
};

String.prototype.symbolize = function() {
return Johnson.symbolize(this.toString());
};

String.prototype.intern = String.prototype.symbolize;

Johnson.Generator = function(enumerableProxy) {
this.items = enumerableProxy.toArray();
this.index = 0;
Expand Down
10 changes: 9 additions & 1 deletion test/johnson/prelude_test.rb
Expand Up @@ -9,6 +9,14 @@ def setup
def test_symbols_are_interned
assert(@context.evaluate("Johnson.symbolize('foo') === Johnson.symbolize('foo')"))
end

def test_strings_can_be_symbolized
assert_js_equal(:monkeys, "'monkeys'.symbolize()")
end

def test_intern_is_a_synonym_for_symbolize
assert_js_equal(:monkeys, "'monkeys'.intern()")
end

def test_symbol_to_string
assert_equal("monkey", @context.evaluate("Johnson.symbolize('monkey').toString()"))
Expand Down Expand Up @@ -39,7 +47,7 @@ def test_missing_requires_throw_LoadError
var flag = false;
try { Johnson.require("johnson/__nonexistent"); }
catch(FileNotFound) { flag = true; }
catch(ex) { flag = true; }
flag;
END
Expand Down

0 comments on commit bdc27a9

Please sign in to comment.