These are chat archives for opal/opal

17th
Jul 2018
Elia Schito
@elia
Jul 17 2018 17:59
@/all Opal v0.11.1 is out! https://rubygems.org/gems/opal/versions/0.11.1

0.11.1 - 2018-07-17

Added

  • Added support for a static folder in the "server" CLI runner via the OPAL_CLI_RUNNERS_SERVER_STATIC_FOLDER env var
  • Added ability to pass the port to the "server" CLI runner using the OPAL_CLI_RUNNERS_SERVER_PORT (explicit option passed via CLI is still working but depreted)
  • Added a new Opal::Config.missing_require_severity option and relative --missing-require CLI flag. This option will command how the builder will behave when a required file is missing. Previously the behavior was undefined and partly controlled by dynamic_require_severity. Not to be confused with the runtime config option Opal.config.missing_require_severity; which controls the runtime behavior.
  • At run-time LoadError wasn't being raised even with Opal.config.missing_require_severity; set to 'error'.
Jan Biedermann
@janbiedermann
Jul 17 2018 19:36
:tada: :tada: :+1:
Elia Schito
@elia
Jul 17 2018 21:59

@/all I was thinking about putting a more detailed example in the /try section of the site, the code would be this:

def title title
  puts '~' * (title.size+4)
  puts "~ #{title} ~"
  puts '~' * (title.size+4)
  puts
  yield
  puts
  puts
end

title "Interacting with the DOM API" do

  require 'native'

  puts "The page title is #{$$[:document][:title].inspect}."
  puts "You're viewing #{$$[:location][:href]}."

  # Uncomment the following lines:
  #
  #   name = $$.prompt "Please enter your name
  #   $$.alert("Hello #{name}!")
  #
end



title "Classes, objects and procs" do

  class User
    attr_accessor :name

    def initialize(name)
      @name = name
    end

    def admin?
      @name == 'Joe'
    end

    def method_missing(name, *args, &block)
      if name.start_with?('can_') && name.end_with?('?')
        admin? ? true : false
      end
    end
  end

  bob = User.new('Bob')
  joe = User.new('Joe')

  user_is_admin = -> user do
    "#{user.name} #{user.admin? ? 'is' : 'is not'} an admin."
  end

  user_can_swim = -> user, action do
    "#{user.name} #{user.can_swim? ? 'can' : 'cannot'} swim."
  end

  puts user_is_admin.call joe
  puts user_can_swim.call joe
  puts user_is_admin.call bob
  puts user_can_swim.call bob
end

with the following output:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~ Interacting with the DOM API ~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The page title is "Try Opal: Browser compiler and REPL".
You're viewing http://opalrb.com/try/.


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~ Classes, objects and procs ~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Joe is an admin.
Joe can swim.
Bob is not an admin.
Bob cannot swim.

Any thoughts? Is it too much/too complicated?

https://bit.ly/2L29qvt

Elia Schito
@elia
Jul 17 2018 22:18
https://bit.ly/2moACWg fixed the commented code