Ledger Nano X - The secure hardware wallet
SHARE
TWEET

Untitled

a guest Apr 5th, 2020 126 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class Implementations
  2.   def initialize(array)
  3.     @array = array
  4.   end
  5.  
  6.   def valid?
  7.     return false if @array.empty?
  8.     true
  9.   end
  10.  
  11.   def if_block_given?
  12.     return true if block_given?
  13.     false
  14.   end
  15.  
  16.   def my_map
  17.     my_array = []
  18.     element = 0
  19.     until @array.size <= element
  20.       my_array << yield(@array[element])
  21.       element += 1
  22.     end
  23.     my_array
  24.   end
  25.  
  26.   def my_select
  27.     my_array = []
  28.     element = 0
  29.     until @array.size <= element
  30.       my_array << (@array[element]) if yield(@array[element])
  31.       element += 1
  32.     end
  33.     my_array
  34.   end
  35.  
  36.   def my_each
  37.     element = 0
  38.     until @array.size <= element
  39.       yield(@array[element])
  40.       element += 1
  41.     end
  42.   end
  43. end
  44.  
  45. output_array = Implementations.new([1, 2, 3])
  46.  
  47. p output_array.my_map {|element| element + 1}
  48. puts
  49. p output_array.my_select {|element| element > 2}
  50. puts
  51. output_array.my_each do |element|
  52.   puts element * 2
  53. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top