This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'net/http' | |
| require 'uri' | |
| require 'async' | |
| require 'benchmark' | |
| bm = Benchmark.measure("Asynchronous flow") do | |
| Async do | |
| results = 21.times.map do |url| | |
| Async do | |
| Net::HTTP.get_response(URI("https://dog.ceo/api/breeds/image/random"),) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| worker = nil | |
| manager = Fiber.new do |work_for_manager| | |
| puts "Manager starting the work" | |
| puts "Doing the work...(Manager)" | |
| puts work_for_manager | |
| puts "Ending the work..(Manager)" | |
| worker.transfer("Do this now - Manager") | |
| puts "Approving - Manager" | |
| puts "Manager logging off" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| fiber = Fiber.new do | |
| n = 1 | |
| while n <= 30 do | |
| Fiber.yield (1..n).inject(&:*) | |
| n = n + 1 | |
| end | |
| end | |
| while fiber.alive? | |
| puts fiber.resume |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { React } from 'react'; | |
| import Axios from 'axios'; | |
| class Demo extends React.Component{ | |
| initialize(){ | |
| this.state = { | |
| userInput: nil, | |
| employees: [], | |
| status: nil | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Human | |
| attr_accessor :first_name, :last_name | |
| def initialize(first_name, last_name) | |
| @first_name = first_name | |
| @last_name = last_name | |
| end | |
| def full_name | |
| "#{first_name} #{last_name}" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| [1,2,3,4,5].method(:length).source_location | |
| #=> nil | |
| "Ruby".method(:concat).source_location | |
| #=> nil | |
| class Array | |
| def subset?(sub_array) | |
| sub_array.each do |element| | |
| return false unless self.include?(element) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module Configurable | |
| def is_a | |
| wrapper(true) | |
| end | |
| def is_not_a | |
| wrapper(false) | |
| end | |
| private |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'active_record' | |
| ActiveRecord::Base.method(:new).owner | |
| #=> ActiveRecord::Inheritance::ClassMethods | |
| ActiveRecord::Base.method(:create).owner | |
| #=> ActiveRecord::Persistence::ClassMethods | |
| ActiveRecord::Base.method(:update).owner | |
| #=> ActiveRecord::Querying |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # A simple class in Ruby | |
| class Human | |
| def introduce | |
| "Hi, I am a #{self.class.name}" | |
| end | |
| end | |
| Human.ancestors | |
| #=> [Human, Object, Kernel, BasicObject] | |
| # Object is present in Human class's ancestor tree. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class A | |
| end | |
| class B < A | |
| end | |
| class C < B | |
| end | |
| A.descendants |
NewerOlder