<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>
  Module: Puppeteer::EventCallbackable
  
    &mdash; Documentation by YARD 0.9.24
  
</title>

  <link rel="stylesheet" href="../css/style.css" type="text/css" />

  <link rel="stylesheet" href="../css/common.css" type="text/css" />

<script type="text/javascript">
  pathId = "Puppeteer::EventCallbackable";
  relpath = '../';
</script>


  <script type="text/javascript" charset="utf-8" src="../js/jquery.js"></script>

  <script type="text/javascript" charset="utf-8" src="../js/app.js"></script>


  </head>
  <body>
    <div class="nav_wrap">
      <iframe id="nav" src="../class_list.html?1"></iframe>
      <div id="resizer"></div>
    </div>

    <div id="main" tabindex="-1">
      <div id="header">
        <div id="menu">
  
    <a href="../_index.html">Index (E)</a> &raquo;
    <span class='title'><span class='object_link'><a href="../Puppeteer.html" title="Puppeteer (class)">Puppeteer</a></span></span>
     &raquo; 
    <span class="title">EventCallbackable</span>
  
</div>

        <div id="search">
  
    <a class="full_list_link" id="class_list_link"
        href="../class_list.html">

        <svg width="24" height="24">
          <rect x="0" y="4" width="24" height="4" rx="1" ry="1"></rect>
          <rect x="0" y="12" width="24" height="4" rx="1" ry="1"></rect>
          <rect x="0" y="20" width="24" height="4" rx="1" ry="1"></rect>
        </svg>
    </a>
  
</div>
        <div class="clear"></div>
      </div>

      <div id="content"><h1>Module: Puppeteer::EventCallbackable
  
  
  
</h1>
<div class="box_info">
  

  
  
  
  
  

  
  <dl>
    <dt>Included in:</dt>
    <dd><span class='object_link'><a href="Browser.html" title="Puppeteer::Browser (class)">Browser</a></span>, <span class='object_link'><a href="BrowserContext.html" title="Puppeteer::BrowserContext (class)">BrowserContext</a></span>, <span class='object_link'><a href="CDPSession.html" title="Puppeteer::CDPSession (class)">CDPSession</a></span>, <span class='object_link'><a href="Connection.html" title="Puppeteer::Connection (class)">Connection</a></span>, <span class='object_link'><a href="FrameManager.html" title="Puppeteer::FrameManager (class)">FrameManager</a></span>, <span class='object_link'><a href="NetworkManager.html" title="Puppeteer::NetworkManager (class)">NetworkManager</a></span>, <span class='object_link'><a href="Page.html" title="Puppeteer::Page (class)">Page</a></span></dd>
  </dl>
  

  
  <dl>
    <dt>Defined in:</dt>
    <dd>lib/puppeteer/event_callbackable.rb</dd>
  </dl>
  
</div>

<h2>Defined Under Namespace</h2>
<p class="children">
  
    
  
    
      <strong class="classes">Classes:</strong> <span class='object_link'><a href="EventCallbackable/EventListeners.html" title="Puppeteer::EventCallbackable::EventListeners (class)">EventListeners</a></span>
    
  
</p>







  
    <h2>
      Instance Method Summary
      <small><a href="#" class="summary_toggle">collapse</a></small>
    </h2>

    <ul class="summary">
      
        <li class="public ">
  <span class="summary_signature">
    
      <a href="#add_event_listener-instance_method" title="#add_event_listener (instance method)">#<strong>add_event_listener</strong>(event_name, &amp;block)  &#x21d2; Object </a>
    

    
  </span>
  
  
  
  
  
  
  

  
    <span class="summary_desc"><div class='inline'></div></span>
  
</li>

      
        <li class="public ">
  <span class="summary_signature">
    
      <a href="#emit_event-instance_method" title="#emit_event (instance method)">#<strong>emit_event</strong>(event_name, *args, **kwargs)  &#x21d2; Object </a>
    

    
  </span>
  
  
  
  
  
  
  

  
    <span class="summary_desc"><div class='inline'></div></span>
  
</li>

      
        <li class="public ">
  <span class="summary_signature">
    
      <a href="#on_event-instance_method" title="#on_event (instance method)">#<strong>on_event</strong>(event_name, &amp;block)  &#x21d2; Object </a>
    

    
  </span>
  
  
  
  
  
  
  

  
    <span class="summary_desc"><div class='inline'></div></span>
  
</li>

      
        <li class="public ">
  <span class="summary_signature">
    
      <a href="#remove_event_listener-instance_method" title="#remove_event_listener (instance method)">#<strong>remove_event_listener</strong>(*id_args)  &#x21d2; Object </a>
    

    
  </span>
  
  
  
  
  
  
  

  
    <span class="summary_desc"><div class='inline'></div></span>
  
</li>

      
    </ul>
  



  <div id="instance_method_details" class="method_details_list">
    <h2>Instance Method Details</h2>

    
      <div class="method_details first">
  <h3 class="signature first" id="add_event_listener-instance_method">
  
    #<strong>add_event_listener</strong>(event_name, &amp;block)  &#x21d2; <tt>Object</tt> 
  

  

  
</h3><table class="source_code">
  <tr>
    <td>
      <pre class="lines">


29
30
31
32</pre>
    </td>
    <td>
      <pre class="code"><span class="info file"># File 'lib/puppeteer/event_callbackable.rb', line 29</span>

<span class='kw'>def</span> <span class='id identifier rubyid_add_event_listener'>add_event_listener</span><span class='lparen'>(</span><span class='id identifier rubyid_event_name'>event_name</span><span class='comma'>,</span> <span class='op'>&amp;</span><span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span>
  <span class='ivar'>@event_listeners</span> <span class='op'>||=</span> <span class='lbrace'>{</span><span class='rbrace'>}</span>
  <span class='lparen'>(</span><span class='ivar'>@event_listeners</span><span class='lbracket'>[</span><span class='id identifier rubyid_event_name'>event_name</span><span class='rbracket'>]</span> <span class='op'>||=</span> <span class='const'><span class='object_link'><a href="EventCallbackable/EventListeners.html" title="Puppeteer::EventCallbackable::EventListeners (class)">EventListeners</a></span></span><span class='period'>.</span><span class='id identifier rubyid_new'><span class='object_link'><a href="EventCallbackable/EventListeners.html#initialize-instance_method" title="Puppeteer::EventCallbackable::EventListeners#initialize (method)">new</a></span></span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_add'>add</span><span class='lparen'>(</span><span class='op'>&amp;</span><span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span>
<span class='kw'>end</span></pre>
    </td>
  </tr>
</table>
</div>
    
      <div class="method_details ">
  <h3 class="signature " id="emit_event-instance_method">
  
    #<strong>emit_event</strong>(event_name, *args, **kwargs)  &#x21d2; <tt>Object</tt> 
  

  

  
</h3><table class="source_code">
  <tr>
    <td>
      <pre class="lines">


47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87</pre>
    </td>
    <td>
      <pre class="code"><span class="info file"># File 'lib/puppeteer/event_callbackable.rb', line 47</span>

<span class='kw'>def</span> <span class='id identifier rubyid_emit_event'>emit_event</span><span class='lparen'>(</span><span class='id identifier rubyid_event_name'>event_name</span><span class='comma'>,</span> <span class='op'>*</span><span class='id identifier rubyid_args'>args</span><span class='comma'>,</span> <span class='op'>**</span><span class='id identifier rubyid_kwargs'>kwargs</span><span class='rparen'>)</span>
  <span class='ivar'>@event_callbackable_handlers</span> <span class='op'>||=</span> <span class='lbrace'>{</span><span class='rbrace'>}</span>
  <span class='ivar'>@event_listeners</span> <span class='op'>||=</span> <span class='lbrace'>{</span><span class='rbrace'>}</span>

  <span class='kw'>if</span> <span class='id identifier rubyid_kwargs'>kwargs</span><span class='period'>.</span><span class='id identifier rubyid_empty?'>empty?</span>
    <span class='comment'># In Ruby&#39;s specification (version &lt; 2.7),
</span>    <span class='comment'># `method(:x).call(*args, **kwargs)` is equivalent to `x(*args, {})`
</span>    <span class='comment'># It often causes unexpected ArgumentError.
</span>    <span class='comment'>#
</span>    <span class='comment'># ----------------
</span>    <span class='comment'># def greet
</span>    <span class='comment'>#   puts &#39;Hello!&#39;
</span>    <span class='comment'># end
</span>    <span class='comment'>#
</span>    <span class='comment'># def call_me(*args, **kwargs)
</span>    <span class='comment'>#   greet(*args, **kwargs) # =&gt; &#39;Hello!&#39;
</span>    <span class='comment'>#
</span>    <span class='comment'>#   method(:greet).call(*args, **kwargs) # =&gt; `greet&#39;: wrong number of arguments (given 1, expected 0) (ArgumentError)
</span>    <span class='comment'># end
</span>    <span class='comment'>#
</span>    <span class='comment'># call_me
</span>    <span class='comment'># ----------------
</span>    <span class='comment'>#
</span>    <span class='comment'># This behavior is really annoying, and should be avoided, because we often want to set event handler as below:
</span>    <span class='comment'>#
</span>    <span class='comment'># `on_event &#39;Some.Event.awesome&#39;, &amp;method(:handle_awesome_event)`
</span>    <span class='comment'>#
</span>    <span class='comment'># So Let&#39;s avoid it by checking kwargs.
</span>    <span class='ivar'>@event_callbackable_handlers</span><span class='lbracket'>[</span><span class='id identifier rubyid_event_name'>event_name</span><span class='rbracket'>]</span><span class='op'>&amp;.</span><span class='id identifier rubyid_call'>call</span><span class='lparen'>(</span><span class='op'>*</span><span class='id identifier rubyid_args'>args</span><span class='rparen'>)</span>
    <span class='ivar'>@event_listeners</span><span class='lbracket'>[</span><span class='id identifier rubyid_event_name'>event_name</span><span class='rbracket'>]</span><span class='op'>&amp;.</span><span class='id identifier rubyid_each'>each</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_proc'>proc</span><span class='op'>|</span>
      <span class='id identifier rubyid_proc'>proc</span><span class='period'>.</span><span class='id identifier rubyid_call'>call</span><span class='lparen'>(</span><span class='op'>*</span><span class='id identifier rubyid_args'>args</span><span class='rparen'>)</span>
    <span class='kw'>end</span>
  <span class='kw'>else</span>
    <span class='ivar'>@event_callbackable_handlers</span><span class='lbracket'>[</span><span class='id identifier rubyid_event_name'>event_name</span><span class='rbracket'>]</span><span class='op'>&amp;.</span><span class='id identifier rubyid_call'>call</span><span class='lparen'>(</span><span class='op'>*</span><span class='id identifier rubyid_args'>args</span><span class='comma'>,</span> <span class='op'>**</span><span class='id identifier rubyid_kwargs'>kwargs</span><span class='rparen'>)</span>
    <span class='ivar'>@event_listeners</span><span class='lbracket'>[</span><span class='id identifier rubyid_event_name'>event_name</span><span class='rbracket'>]</span><span class='op'>&amp;.</span><span class='id identifier rubyid_each'>each</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_proc'>proc</span><span class='op'>|</span>
      <span class='id identifier rubyid_proc'>proc</span><span class='period'>.</span><span class='id identifier rubyid_call'>call</span><span class='lparen'>(</span><span class='op'>*</span><span class='id identifier rubyid_args'>args</span><span class='comma'>,</span> <span class='op'>**</span><span class='id identifier rubyid_kwargs'>kwargs</span><span class='rparen'>)</span>
    <span class='kw'>end</span>
  <span class='kw'>end</span>

  <span class='id identifier rubyid_event_name'>event_name</span>
<span class='kw'>end</span></pre>
    </td>
  </tr>
</table>
</div>
    
      <div class="method_details ">
  <h3 class="signature " id="on_event-instance_method">
  
    #<strong>on_event</strong>(event_name, &amp;block)  &#x21d2; <tt>Object</tt> 
  

  

  
</h3><table class="source_code">
  <tr>
    <td>
      <pre class="lines">


42
43
44
45</pre>
    </td>
    <td>
      <pre class="code"><span class="info file"># File 'lib/puppeteer/event_callbackable.rb', line 42</span>

<span class='kw'>def</span> <span class='id identifier rubyid_on_event'>on_event</span><span class='lparen'>(</span><span class='id identifier rubyid_event_name'>event_name</span><span class='comma'>,</span> <span class='op'>&amp;</span><span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span>
  <span class='ivar'>@event_callbackable_handlers</span> <span class='op'>||=</span> <span class='lbrace'>{</span><span class='rbrace'>}</span>
  <span class='ivar'>@event_callbackable_handlers</span><span class='lbracket'>[</span><span class='id identifier rubyid_event_name'>event_name</span><span class='rbracket'>]</span> <span class='op'>=</span> <span class='id identifier rubyid_block'>block</span>
<span class='kw'>end</span></pre>
    </td>
  </tr>
</table>
</div>
    
      <div class="method_details ">
  <h3 class="signature " id="remove_event_listener-instance_method">
  
    #<strong>remove_event_listener</strong>(*id_args)  &#x21d2; <tt>Object</tt> 
  

  

  
</h3><table class="source_code">
  <tr>
    <td>
      <pre class="lines">


34
35
36
37
38
39
40</pre>
    </td>
    <td>
      <pre class="code"><span class="info file"># File 'lib/puppeteer/event_callbackable.rb', line 34</span>

<span class='kw'>def</span> <span class='id identifier rubyid_remove_event_listener'>remove_event_listener</span><span class='lparen'>(</span><span class='op'>*</span><span class='id identifier rubyid_id_args'>id_args</span><span class='rparen'>)</span>
  <span class='lparen'>(</span><span class='ivar'>@event_listeners</span> <span class='op'>||=</span> <span class='lbrace'>{</span><span class='rbrace'>}</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_each'>each</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_event_name'>event_name</span><span class='comma'>,</span> <span class='id identifier rubyid_listeners'>listeners</span><span class='op'>|</span>
    <span class='id identifier rubyid_id_args'>id_args</span><span class='period'>.</span><span class='id identifier rubyid_each'>each</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_id'>id</span><span class='op'>|</span>
      <span class='id identifier rubyid_listeners'>listeners</span><span class='period'>.</span><span class='id identifier rubyid_delete'>delete</span><span class='lparen'>(</span><span class='id identifier rubyid_id'>id</span><span class='rparen'>)</span>
    <span class='kw'>end</span>
  <span class='kw'>end</span>
<span class='kw'>end</span></pre>
    </td>
  </tr>
</table>
</div>
    
  </div>

</div>

      <div id="footer">
  Generated on Fri Jun 12 12:38:32 2020 by
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
  0.9.24 (ruby-2.6.3).
</div>

    </div>
  </body>
</html>