Skip to content

Features

Shozo Hatta edited this page Jun 10, 2018 · 2 revisions

Language

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
    • 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]
    • 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
  • Constant
    • Starts with uppercase like Var or VAR
    • Global if defined on top-level
    • not reentrant by assignment, but still permits redefining class/module
    • special variables with $ are unsupported
  • Methods
    • Definition: order of parameters are strictly determined:
      1. normal params (ex: a, b) -- default value with = is optional
      2. opt params (ex: ary=[], hs={}) -- [] or {} cannot be omitted on the callers' args
      3. keyword params (ex: mail: tel:) -- default value = is optional
      4. splat params (ex: *sp) for compatibility with Go functions
    • Evaluation with/without arguments
    • Evaluation with a block (closure)
    • Defining singleton methods
    • attr_accessor, attr_reader, attr_writer
  • Block
    • do - end
  • Flow control
    • if, else, elsif
    • while
    • raise
  • Literals
    • Numeric literal
      • Integer: 100, -299, -0
      • Float: 3.14, -273.15
    • 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
    • Array literal: [1, "2", '3', :att]
    • Hash literal: { "email": '[email protected]', tel: '9909-999-999'}
  • 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, like chan in Go
    • See this sample: One thousand threads
  • 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 or raise

Native classes

Written in Go.

  • Class
  • Integer
  • String
    • Symbols like :a or hash keys {a: 1} are just another notation of String
  • 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

Standard libraries

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!)