Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
rubyish - implement compound-statement/multi-line interpolation
- Loading branch information
Showing
3 changed files
with
19 additions
and
11 deletions.
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,21 +1,22 @@ | ||
| puts "1..4" | ||
| puts "1..5" | ||
|
|
||
| def capitalize(s) | ||
| nqp::uc(nqp::substr(s, 0, 1)) ~ nqp::lc(nqp::substr(s, 1)); | ||
| end | ||
|
|
||
| class HelloWorld | ||
| puts "ok 1 - class immediate code" | ||
| def initialize(name) | ||
| puts "ok 1 - initialize called" | ||
| puts "ok 2 - initialize called" | ||
| @name = capitalize name | ||
| end | ||
| def sayHi | ||
| puts "ok 4 - Hello #{@name}!" | ||
| puts "ok 5 - Hello #{@name}!" | ||
| end | ||
| end | ||
|
|
||
| hello = HelloWorld.new("worldish") | ||
| puts "#{nqp::can(hello, 'sayHi')? 'ok' : 'nok'} 2 - can say Hi" | ||
| puts "#{nqp::can(hello, 'sayBye')? 'nok' : 'ok'} 3 - can't say Bye" | ||
| puts "#{nqp::can(hello, 'sayHi')? 'ok' : 'nok'} 3 - can say Hi" | ||
| puts "#{nqp::can(hello, 'sayBye')? 'nok' : 'ok'} 4 - can't say Bye" | ||
| hello.sayHi | ||
|
|
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,18 @@ | ||
| puts "1..8" | ||
| puts "1..10" | ||
| a = 2 | ||
| puts "ok #{1} - num" | ||
| puts "ok #{a} - variable" | ||
| puts "ok #{a+1} - expression" | ||
| b = 'ok' | ||
| puts "#{b} #{3*(a - 1) + 1} - expression" | ||
| puts %q<ok 5> ' - %q<...>' | ||
| tst=5 | ||
| puts %q<ok> " #{tst}" ' - adjacent' ' strings' | ||
| puts %Q{ok #{a*=3} - expression - side affect} | ||
| puts %Q{ok #{(a+=2)-1} - expression - side affect} | ||
| puts "#{if a==8 then 'ok' else 'nok' end} #{a} - nested statement" | ||
| puts "ok 9 # todo nested starters / stoppers" | ||
| ##puts "#{'#{tst}' == '#{' 'tst}'? 'ok' : 'nok'} 9 - nested starters / stoppers" | ||
| puts "ok #{ | ||
| x = 4; x+= 1 | ||
| x+5 | ||
| } - multiline interpolation" |