Class: IRuby::DisplayHook

Inherits:
Object
  • Object
show all
Defined in:
lib/iruby/display_hook.rb

Instance Method Summary collapse

Constructor Details

#initialize(kernel, session, pub_socket) ⇒ DisplayHook

Returns a new instance of DisplayHook.



5
6
7
8
9
10
# File 'lib/iruby/display_hook.rb', line 5

def initialize kernel, session, pub_socket
  @kernel = kernel
  @session = session
  @pub_socket = pub_socket
  @parent_header = {}
end

Instance Method Details

#display(obj) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/iruby/display_hook.rb', line 12

def display(obj)
  if obj.nil?
    return
  end
  # STDERR.puts @kernel.user_ns
  # @user_ns._ = obj
  # STDERR.puts "displayhook call:"
  # STDERR.puts @parent_header.inspect
  #@pub_socket.send(msg.to_json)
  data = {}
  output = obj
  data['text/plain'] = output
  data[obj.mime] =  output
  content = {data: data, metadata: {}, execution_count: @kernel.execution_count}
  @session.send(@pub_socket, 'pyout', content, @parent_header)
end

#set_parent(parent) ⇒ Object



29
30
31
# File 'lib/iruby/display_hook.rb', line 29

def set_parent parent
  @parent_header = Message.extract_header(parent)
end