ruby - What is Camping::Server.start invoking in /bin/camping? -
i'm studying how camping
web framework works right now, , don't understand camping::server.start
@ line 10 in /bin/camping
doing.
i expected call start
method in /lib/camping/server.rb
@ line 131, , put simple puts 'hello'
statement @ beginning of method, expecting statement invoked when ran /bin/camping
. however, never saw puts statement called, can assume it's not start
method getting called.
i feel i'm missing obvious here. here link camping github page , relevant sections of code:
github: https://github.com/camping/camping
from /bin/camping
:
#!/usr/bin/env ruby $:.unshift file.dirname(__file__) + "/../lib" require 'camping' require 'camping/server' begin camping::server.start rescue optionparser::parseerror => ex puts "did error" stderr.puts "!! #{ex.message}" puts "** use `#{file.basename($0)} --help` more details..." exit 1 end
from /lib/server.rb
:
def start if options[:server] == "console" puts "** starting console" @reloader.reload! r = @reloader eval("self", toplevel_binding).meta_def(:reload!) { r.reload!; nil } argv.clear irb.start exit else name = server.name[/\w+$/] puts "** starting #{name} on #{options[:host]}:#{options[:port]}" super end end
my puts 'hello'
on camping::server.start
wasn't getting called because didn't understand how static methods defined in ruby.
start
being called statically, , realize start
method looking @ in snippet wasn't static method, meant start
method getting called. looked camping::server
, realized inherited rack::server
, has following method:
def self.start(options = nil) new(options).start end
that method getting called, not 1 on /lib/camping/server.rb
. had been looking @ wrong method.
Comments
Post a Comment