Rafa_F
January 22, 2016, 6:46pm
1
Hi,
I’m looking over some code (Asciidoctor), and in one file there are
several ‘define’ statements enclosed in a module. An example of this is
the following in a .rb file:
define :block_terminates_paragraph, true
define :strict_verbatim_paragraphs, true
I’ve seen ‘define_method’ documented but not the keyword ‘define’. It
seems like it might be defining symbolic constants, but I’m not sure.
Could someone clarify this?
Thanks.
Les
It’s not a keyword, it’s a (class) method defined by asciidoctor.
See here for the source:
# encoding: UTF-8
RUBY_ENGINE = 'unknown' unless defined? RUBY_ENGINE
RUBY_ENGINE_OPAL = (RUBY_ENGINE == 'opal')
RUBY_ENGINE_JRUBY = (RUBY_ENGINE == 'jruby')
RUBY_MIN_VERSION_1_9 = (RUBY_VERSION >= '1.9')
RUBY_MIN_VERSION_2 = (RUBY_VERSION >= '2')
require 'set'
# NOTE RUBY_ENGINE == 'opal' conditional blocks are filtered by the Opal preprocessor
if RUBY_ENGINE == 'opal'
# NOTE asciidoctor/opal_ext is supplied by the Asciidoctor.js build
require 'asciidoctor/opal_ext'
else
autoload :Base64, 'base64'
autoload :FileUtils, 'fileutils'
autoload :OpenURI, 'open-uri'
autoload :StringScanner, 'strscan'
end
This file has been truncated. show original
Defines a new compliance key and
assigns an initial value.
def self.define key, value
instance_variable_set %(@#{key}),
value
class << self
self
end.send :attr_accessor, key
@keys << key
nil
end