-
Notifications
You must be signed in to change notification settings - Fork 171
Features
Shozo Hatta edited this page Jun 10, 2018
·
2 revisions
Perhaps Goby should be far easier for Rubyists to comprehend. You can use Ruby's syntax highlighting for Goby as well😀
- Everything is object
- Object and Class
- Top level main object
- Constructor by
.initialize
- Class/instance method
- Class
- Can be inherited with
<
- Singleton class
-
Class.ancestors #» [Class, Module, Object]
-
Class.new
is possible
-
#send
- Can be inherited with
self
- Module for supporting mixin
-
#include
for instance methods -
#extend
for class methods -
Module.new
is possible- but cannot perform
#new
on modules' instances Module.ancestors #» [Module, Object]
- but cannot perform
- Modules cannot inherit classes/modules
- Modules cannot be inherited by classes
-
- Namespace
-
::
for delimiting namespaces for class/module/constants
-
- Variable: starts with lowercase letter like
var
- Local variable like
mail
,tel
- Instance variable like
@mail
,@tel
- Class variables: unsupported
- Local variable like
- Constant
- Starts with uppercase like
Var
orVAR
- Global if defined on top-level
- not reentrant by assignment, but still permits redefining class/module
- special variables with
$
are unsupported
- Starts with uppercase like
- Methods
- Definition: order of parameters are strictly determined:
- normal params (ex:
a
,b
) -- default value with=
is optional - opt params (ex:
ary=[]
,hs={}
) --[]
or{}
cannot be omitted on the callers' args - keyword params (ex:
mail:
tel:
) -- default value=
is optional - splat params (ex:
*sp
) for compatibility with Go functions
- normal params (ex:
- Evaluation with/without arguments
- Evaluation with a block (closure)
- Defining singleton methods
-
attr_accessor
,attr_reader
,attr_writer
- Definition: order of parameters are strictly determined:
- Block
-
do
-end
-
- Flow control
-
if
,else
,elsif
while
raise
-
- Literals
- Numeric literal
- Integer:
100
,-299
,-0
- Float:
3.14
,-273.15
- Integer:
- String literal:
"candy"
,'cake'
,:taffy
- Symbol literal:
:email
- Symbol literal is
String
class and just a convenient representation for Rubyists.- So you can even do like:
a = :bar.replace("a", "z"); puts a #=> bzr
- So you can even do like:
- Symbol literal is
- Array literal:
[1, "2", '3', :att]
- Hash literal:
{ "email": '[email protected]', tel: '9909-999-999'}
- Numeric literal
- IO
#puts
-
ARGV
,STDIN
,STDOUT
,STDERR
,ENV
constants
- Import files
-
require
(Just for standard libraries by now) require_relative
-
- Thread (not a class!)
- Goroutine-based
thread
method to create a new thread - Works with
Channel
class for passing objects between threads, likechan
in Go - See this sample: One thousand threads
- Goroutine-based
- Very few keywords
-
def
,true
,false
,nil
,if
,elsif
,else
,case
,when
,return
,self
,end
,while
,do
,yield
,next
,class
,module
,break
,get_block
- Most are implemented as methods, including
thread
orraise
-
Written in Go.
Class
Integer
-
String
- Symbols like
:a
or hash keys{a: 1}
are just another notation ofString
- Symbols like
Boolean
-
Null
(nil
) Hash
Array
Range
URI
Channel
File
-
GoObject
(provides#go_func
that wraps pure Go objects or pointers for interaction) Regexp
-
MatchData
(to hold the result of regexp matching) Float
-
Decimal
- Represented as a fraction internally
- Number of digits has virtually no limit
- You can get Decimal object as for now:
a = "-99.99999999".to_d
-
Block
- This can perform
.new
taking a block to generate a block object (similar to Ruby's proc object) - The block object can perform
#call
to execute the block
- This can perform
written in Go and Goby.
Concurrent::Array
Concurrent::Hash
-
DB
(only for PostgreSQL by now) Plugin
JSON
Net::HTTP
Net::HTTP::Client
Net::HTTP::Request
Net::HTTP::Response
-
Net::SimpleServer
(try sample Goby app and source, or sample code!)