gistlib
other ruby categories
ruby code snippets in ruby
"these series are only required to occupy adjacent positions in the input; the digits need not be numerically consecutive" what does it mean? show examples in ruby
"would you like #{first + second} to be your new fav number?" how to add with interpolation? in ruby
250741 is what i want to convert to an int array in ruby
[{:s, 1, :xl, 4}] is returned to me. i want to only return {:s, 1, :xl, 4}. how to? in ruby
a function to flatten a nested array, if it contains nil, removes the nils, if its elements are all nil, return empty array. in ruby
a s.txt file is in the current directory; write a ruby function that reads this file and prints its contents to screen. in ruby
a shorter way to do `class year def self.hi puts "hi" end end`? in ruby
a shorter way to do: ` arr = %w[black brown red orange yellow green blue violet grey white] cols = arr.each_with_index.map {|col , ind| [col, ind.to_s]}.to_h` in ruby
add a getter to a class in ruby
add a getter to a subclass in ruby
add a key-value pair to a map in ruby
add a method to a class in ruby
add a method to a subclass in ruby
add a node to the beginning of a linked list in ruby
add a node to the end of a linked list in ruby
add a private method to a class in ruby
add a private property to a class in ruby
add a private static method to a class in ruby
add a private static property to a class in ruby
add a property to a class in ruby
add a protected method to a class in ruby
add a protected property to a class in ruby
add a protected static method to a class in ruby
add a protected static property to a class in ruby
add a public method to a class in ruby
add a public property to a class in ruby
add a public static property to a class in ruby
add a setter to a class in ruby
add a setter to a subclass in ruby
add a static method to a class in ruby
add a static method to a subclass in ruby
add a static property to a class in ruby
add an element to the beginning of an array in ruby
add an element to the end of an array in ruby
add cors headers to a http server in ruby
add cors headers to a http server with a specific origin in ruby
add cors headers to a http server with a specific origin and methods in ruby
add two numbers in ruby
append a string to the end of another string in ruby
append to a csv file in ruby
append to a file in ruby
append to a json file in ruby
besides `%w[1 2 3]` what other methods or tricks exist that use % then some letter? in ruby
call a getter on an instance of a class in ruby
call a method on an instance of a class in ruby
call a private property on an instance of a class in ruby
call a private static method on an instance of a class in ruby
call a protected method on an instance of a class in ruby
call a protected property on an instance of a class in ruby
call a protected static method on an instance of a class in ruby
call a protected static property on an instance of a class in ruby
call a public method on an instance of a class in ruby
call a public property on an instance of a class in ruby
call a public static method on an instance of a class in ruby
call a public static property on an instance of a class in ruby
call a setter on an instance of a class in ruby
call a static method on an instance of a class in ruby
call a static property on an instance of a class in ruby
can i write a class method and class on the same line in ruby? in ruby
can you explain how to do this program and what is required? i didn't understand it when i read it: https://exercism.org/tracks/ruby/exercises/resistor-color-duo in ruby
can you patiently explain what happens in this? `words_array.each do |word| word_counts[word] ||= 0 word_counts[word] += 1 end` in ruby
case when in ruby
case-insensitive pangram-checker one-liner function in julia? in ruby
change it to one-liner : `def compute(dn1, dn2) raise argumenterror if dn1.length != dn2.length count = 0 dn1.length.times do |i| count += 1 if dn1[i] != dn2[i] end count end end` in ruby
change to one-liner : `class grains def self.square(n) raise argumenterror unless n.between?(1,64) 2 ** (n - 1) end` in ruby
change to oneliner: `class flattenarray def self.flatten(ar) [] if ar.nil? ar.flatten.compact end end` in ruby
check if array is empty in ruby
check if array is not empty in ruby
check if string starts with a timestamp in ruby
check if string starts with a timestamp and capture suffix in ruby
combine two maps in ruby
compute desired balance in ruby
concatenate two arrays in ruby
convert a number from base 10 to base 16 in ruby
convert a number from base 10 to base 2 in ruby
convert a number from base 2 to base 10 in ruby
convert a number from base 2 to base 16 in ruby
convert a number from base 2 to base 8 in ruby
convert it to a struct: `class series def initialize(series) = @series = series def slices(n) raise argumenterror if n > @series.length @series.chars.each_cons(n).map(&:join) end end` in ruby
convert seconds to minutes in ruby
copy a csv file in ruby
copy a directory in ruby
copy a file in ruby
copy a json file in ruby
count instances of an element inside an array in ruby
count words in array in ruby
create a 3 dimensional array in ruby
create a blake2b hash from a string in ruby
create a caesar cipher function in ruby
create a class in ruby
create a class with a constructor in ruby
create a csv file in ruby
create a directory in ruby
create a file in ruby
create a function that appends text to a string from an input array in ruby
create a function to output an html file with the title and body content and an ordered list from the input array in ruby
create a get request handler in ruby
create a http server and add a custom header to the response in ruby
create a http server and parse authorization headers in ruby
create a http server and parse cookies in ruby
create a http server and parse cookies and return a json response in ruby
create a http server and read the request body in ruby
create a http server and read the request body as binary in ruby
create a http server and read the request body as binary and return a binary response in ruby
create a http server and read the request body as form data in ruby
create a http server and read the request body as form url encoded in ruby
create a http server and read the request body as html in ruby
create a http server and read the request body as json in ruby
create a http server and read the request body as json and return a json response in ruby
create a http server and read the request body as multipart form data in ruby
create a http server and read the request body as text in ruby
create a http server and upload a file and return a binary response in ruby
create a http server on a specific port in ruby
create a http server on a specific port and host in ruby
create a http server with a connect route in ruby
create a http server with a custom route in ruby
create a http server with a get route in ruby
create a http server with a head route in ruby
create a http server with a options route in ruby
create a http server with a patch route in ruby
create a http server with a post route in ruby
create a http server with a put route in ruby
create a http server with a specific route in ruby
create a http server with a specific route and a specific status code in ruby
create a http server with a trace route in ruby
create a json file in ruby
create a linked list in ruby
create a loop in ruby
create a matrix in ruby
create a md5 hash from a string in ruby
create a password in ruby
create a password with a custom length in ruby
create a password with a custom length and lowercase letters in ruby
create a password with a custom length and numbers in ruby
create a password with a custom length and symbols in ruby
create a password with a custom length and uppercase letters in ruby
create a password with a custom length, uppercase letters and lowercase letters in ruby
create a password with at least one lowercase letter in ruby
create a password with at least one number in ruby
create a password with at least one symbol in ruby
create a password with at least one uppercase letter in ruby
create a password with lowercase letters in ruby
create a password with numbers in ruby
create a password with symbols in ruby
create a password with uppercase letters in ruby
create a password with uppercase letters and lowercase letters in ruby
create a password with uppercase, lowercase letters and numbers in ruby
create a password with uppercase, lowercase letters, numbers and symbols in ruby
create a rails model method to send an http post request with basic authorization in ruby
create a retry function in ruby
create a sha1 hash from a string in ruby
create a sha256 hash from a string in ruby
create a sha3_256 hash from a string in ruby
create a sha3_512 hash from a string in ruby
create a sha512 hash from a string in ruby
create a subclass in ruby
create a subclass with a constructor in ruby
create a tcp client in ruby
create a tcp client on a specific port in ruby
create a tcp server in ruby
create a tcp server on a specific port in ruby
create a template string in ruby
create a udp client in ruby
create a udp client on a specific port in ruby
create a udp server in ruby
create a udp server on a specific port in ruby
create an api call to gather nba player stats in ruby
create an array with every book of the bible in it in ruby
create an dictionary with every book of the bible in it where the key is all lowercase and the value is capitalized in ruby
create an empty list, an a list filled with dummy numbers in sml in ruby
create an example function that uses dynamic programming to sort a binary tree in ruby
create an instance of a class with a constructor in ruby
creatye a method to send an http post request with basic authorization in ruby
def initialize method in a class, using attr? in ruby
define a function that takes a string like "m" and displays only the "size" for [{p: 10, n: "m", size: {s: 7, m: 2}}] in ruby
delete a csv file in ruby
delete a directory in ruby
delete a file in ruby
delete a json file in ruby
describe this: ([*'a'..'z'] - phrase.downcase.chars).empty? in ruby
divide two numbers in ruby
even shorter way to do this ? `helloworld = object.new; def helloworld.hello = "hello, world!"` in ruby
example of a function that takes only the first two elements of an array and joins their indexes as an integer in ruby
explain `.sum(0, &cols.method(:[])).to_i` in ruby
explain `[3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5].chunk { |n| n.even? }.each { |even, ary| p [even, ary] }` in ruby
explain `e = (1..3).chain([4, 5]) e.to_a #=> [1, 2, 3, 4, 5]` in ruby
explain this `fibonacci.sum {| number | number * number }` in ruby
explain what "sum" does here and what is &: ` def self.value(colors) colors.first(2).sum('', &color_rules).to_i end` in ruby
explain what each thing does in this regex: (/(.).*\1|\d/i) in ruby
explain what this code does and why `arr = [1, 2, 3, 4, 5] arr.each {|a| print a -= 10, " "}` in ruby
find all the strings matching ‘tony’ in an array of strings, then return how many there are. if there are none then return nil in ruby
find the area of a circle in ruby
find the area of a parallelogram in ruby
find the area of a rectangle in ruby
find the area of a regular polygon in ruby
find the area of a regular polygon circumscribed around a circle in ruby
find the area of a regular polygon inscribed in a circle in ruby
find the area of a sector of a circle in ruby
find the area of a segment of a circle in ruby
find the area of a square in ruby
find the area of a triangle in ruby
find the average of a list of numbers in ruby
find the average of all elements in an array in ruby
find the average of all keys in a map in ruby
find the average of all nodes in a linked list in ruby
find the average of all values in a map in ruby
find the base 10 logarithm of a number in ruby
find the base 2 logarithm of a number in ruby
find the base e logarithm of a number in ruby
find the contents of a directory in ruby
find the creation date of a csv file in ruby
find the creation date of a directory in ruby
find the creation date of a file in ruby
find the creation date of a json file in ruby
find the cube root of a number in ruby
find the current date in ruby
find the current month in ruby
find the current year in ruby
find the difference of two maps in ruby
find the distance between two points in ruby
find the extension of a csv file in ruby
find the extension of a file in ruby
find the factorial of a number in ruby
find the first character in a string in ruby
find the first element in an array in ruby
find the first index of a character in a string in ruby
find the first index of a substring in a string in ruby
find the first node in a linked list in ruby
find the greatest common divisor of a list of numbers in ruby
find the greatest common divisor of two numbers in ruby
find the index of an element in an array in ruby
find the intersection of two maps in ruby
find the key associated with a value in a map in ruby
find the keys of a map in ruby
find the kth character in a string in ruby
find the kth index of a character in a string in ruby
find the kth index of a substring in a string in ruby
find the kth largest element in an array in ruby
find the kth largest key in a map in ruby
find the kth largest node in a linked list in ruby
find the kth largest number in a list in ruby
find the kth least common element in an array in ruby
find the kth least frequent element in an array in ruby
find the kth longest word in a string in ruby
find the kth most common element in an array in ruby
find the kth most frequent element in an array in ruby
find the kth smallest element in an array in ruby
find the kth smallest key in a map in ruby
find the kth smallest number in a list in ruby
find the largest element in an array in ruby
find the largest key in a map in ruby
find the largest value in a map in ruby
find the last accessed date of a csv file in ruby
find the last accessed date of a directory in ruby
find the last accessed date of a file in ruby
find the last character in a string in ruby
find the last element in an array in ruby
find the last index of a character in a string in ruby
find the last index of a substring in a string in ruby
find the last modified date of a csv file in ruby
find the last modified date of a file in ruby
find the last modified date of a json file in ruby
find the last node in a linked list in ruby
find the least common multiple of a list of numbers in ruby
find the least common multiple of two numbers in ruby
find the length of a linked list in ruby
find the length of a map in ruby
find the length of a string in ruby
find the length of an array in ruby
find the logarithm of a number in ruby
find the median of a list of numbers in ruby
find the median of all elements in an array in ruby
find the median of all keys in a map in ruby
find the median of all nodes in a linked list in ruby
find the median of all values in a map in ruby
find the midpoint between two points in ruby
find the mode of a list of numbers in ruby
find the mode of all elements in an array in ruby
find the mode of all keys in a map in ruby
find the mode of all nodes in a linked list in ruby
find the mode of all values in a map in ruby
find the name of a csv file in ruby
find the name of a directory in ruby
find the name of a file in ruby
find the natural logarithm of a number in ruby
find the nth decagonal number in ruby
find the nth fibonacci number in ruby
find the nth hexagonal number in ruby
find the nth lucas number in ruby
find the nth nonagonal number in ruby
find the nth prime number in ruby
find the nth root of a number in ruby
find the nth square number in ruby
find the parent directory of a directory in ruby
find the parent directory of a file in ruby
find the path of a directory in ruby
find the path of a file in ruby
find the path of a json file in ruby
find the range of a list of numbers in ruby
find the range of all elements in an array in ruby
find the range of all keys in a map in ruby
find the range of all nodes in a linked list in ruby
find the range of all values in a map in ruby
find the remainder of two numbers in ruby
find the root directory of a directory in ruby
find the root directory of a file in ruby
find the shortest word in a string in ruby
find the size of a file in ruby
find the size of a json file in ruby
find the slope between two points in ruby
find the smallest key in a map in ruby
find the smallest node in a linked list in ruby
find the smallest value in a map in ruby
find the square root of a number in ruby
find the standard deviation of a list of numbers in ruby
find the standard deviation of all elements in an array in ruby
find the standard deviation of all keys in a map in ruby
find the standard deviation of all nodes in a linked list in ruby
find the standard deviation of all values in a map in ruby
find the sum of a list of numbers in ruby
find the sum of all elements in an array in ruby
find the sum of all keys in a map in ruby
find the sum of all nodes in a linked list in ruby
find the sum of all values in a map in ruby
find the surface area of a cone in ruby
find the surface area of a cylinder in ruby
find the surface area of a rectangular prism in ruby
find the surface area of a regular polygon circumscribed around a cone in ruby
find the surface area of a regular polygon circumscribed around a cylinder in ruby
find the surface area of a regular polygon circumscribed around a pyramid in ruby
find the surface area of a regular polygon circumscribed around a sphere in ruby
find the surface area of a regular polygon circumscribed around a triangular prism in ruby
find the surface area of a regular polygon inscribed in a cone in ruby
find the surface area of a regular polygon inscribed in a cylinder in ruby
find the surface area of a regular polygon inscribed in a pyramid in ruby
find the surface area of a regular polygon inscribed in a sphere in ruby
find the surface area of a regular polygon inscribed in a triangular prism in ruby
find the surface area of a sphere in ruby
find the surface area of a triangular prism in ruby
find the symmetric difference of two maps in ruby
find the union of two maps in ruby
find the value associated with a key in a map in ruby
find the values of a map in ruby
find the variance of a list of numbers in ruby
find the variance of all keys in a map in ruby
find the variance of all nodes in a linked list in ruby
find the variance of all values in a map in ruby
find the volume of a cone in ruby
find the volume of a pyramid in ruby
find the volume of a regular polygon circumscribed around a cone in ruby
find the volume of a regular polygon circumscribed around a cylinder in ruby
find the volume of a regular polygon circumscribed around a pyramid in ruby
find the volume of a regular polygon circumscribed around a sphere in ruby
find the volume of a regular polygon circumscribed around a triangular prism in ruby
find the volume of a regular polygon inscribed in a cone in ruby
find the volume of a regular polygon inscribed in a cylinder in ruby
find the volume of a regular polygon inscribed in a pyramid in ruby
find the volume of a regular polygon inscribed in a sphere in ruby
find the volume of a regular polygon inscribed in a triangular prism in ruby
find the volume of a sphere in ruby
fix : `def convert(n) res = ''; nums = [3, 5, 7]; sounds = %w[pling plang plong]; nums.each |i| { (n % nums[i]).zero? ? res += sounds[i] : (res == '' ? n.to_s : "") } end res end in ruby
fix but keep short and use ternaries: `def convert(n) r = '' n%3 == 0 ? r << 'pling' : n%5 == 0 ? r << 'plang' : n%7 == 0 ? r << 'plong' : r.empty? ? n.to_s : r end` in ruby
fix it: `class isogram def self.isogram?(词) = 词.match(/(\w+).*\1/i) !~ end` in ruby
fix it: `series = struct.new(:string) { def slices(n) = string.each_char.each_cons(n).map(&:join) if n > string.length }` in ruby
fix this `class grains def self.square(n) = 2 ** (n - 1); raise argumenterror if !n.between?(1,64) def self.total = 18_446_744_073_709_551_615 end` in ruby
fix this: class flattenarray def self.flatten(ar) return [] if ar.all?(&:nil?) ar.compact! if ar.include?(nil) ar.flatten end end in ruby
fix: `def conv(n) res = ''; nums = [3, 5, 7]; sounds = ['pling', 'plang', 'plong'] nums.length.times do |i| if n % nums[i] == 0 res << sounds[i] else res.empty? ? n.to_s : res end end end` in ruby
fix: `series = struct.new(:str) { def slices(n) n > @str.length ? argumenterror.new("no!") : str.each_char.each_cons(n).map(&:join) end }` in ruby
for `word = "isogram" result = word.match(/(.)\1|\d/i) p !result` how to change so that hyphenated words are also processed? in ruby
for an input like: `%w[black brown white], write a function that takes the index of 1st element and index of 2nd element and combines them into a digit in ruby
for this array: [{p:10, n:"m", size: {s: 7, m: 2}} how to display only the 'size'? in ruby
format a date in to the format 'yyyy-mm-dd hh:mm:ss' in ruby
format a date in to the format 'yyyy-mm-dd hh:mm:ss.fff zzz' in ruby
format a date in to the format 'yyyy-mm-dd hh:mm:ss.fff' in ruby
format a date in to the format 'yyyy-mm-dd' in ruby
format a date in to the format month day, year in ruby
format a date in to the format month day, year hour:minute am/pm in ruby
format a date in to the format month day, year hour:minute:second am/pm in ruby
format a date in to the format month day, year hour:minute:second.fff am/pm in ruby
format a date in to the format month day, year hour:minute:second.fff am/pm zzz in ruby
format a date in to the format october 13, 2014 in ruby
format a date in to the format october 13, 2014 11:13 am in ruby
format a date in to the format october 13, 2014 11:13:00 am in ruby
format a date in to the format october 13, 2014 11:13:00.000 am in ruby
format a date in to the format october 13, 2014 11:13:00.000 am gmt-07:00 in ruby
format seconds to minutes awnd seconds in ruby
generate a hash from this: `%w[black brown red` such that values are its index. in ruby
generate a random array in ruby
generate a random boolean in ruby
generate a random number in ruby
generate a random number between 0 and 1 in ruby
generate a random number between 1 and 10 in ruby
generate a random number between 1 and 100 in ruby
generate a random string in ruby
generate random string in ruby
generate uuid in ruby
get a random element from an array in ruby
get a random number from a normal distribution with a mean of 0 and a standard deviation of 1 in ruby
get a sample of 5 elements from an array in ruby
get a sample of 5 elements from an array with replacement in ruby
get a sample of 5 elements from an array without replacement in ruby
get a uniformly distributed random number in ruby
get system architecture in ruby
get system boot time in ruby
get system boot time in milliseconds in ruby
get system boot time in minutes in ruby
get system boot time in seconds in ruby
get system cpu frequency in ruby
get system cpu temperature in ruby
get system cpu temperature in celsius in ruby
get system cpu temperature in fahrenheit in ruby
get system cpu usage in ruby
get system free disk space in ruby
get system free memory in ruby
get system name in ruby
get system platform in ruby
get system release in ruby
get system total memory in ruby
get system type in ruby
get system uptime in ruby
get the first 3 characters and last 5 characters in a string then combine into a new string in ruby
gimme a function that take only the first two elements of an array passed to it, even though it can take a variable amount of arguments in ruby
give `1 <= n < 65` as a range in julia in ruby
give `class grains def self.square(n) 2 ** (n - 1) end` like here: `class phrase < struct.new(:text)` a struct like: in ruby
give a one-liner function in julia that checks if a sentence is a pangram and it is case insensitive in ruby
give a regex-based isogram checker in ruby in ruby
give it as a struct: `class series def initialize(string) @string = string end def slices(n) raise argumenterror if n > @string.length @string.each_char.each_cons(n).map(&:join) end end` in ruby
give me a function that does this: input: [1,[2,3,null,4],[null],5] output: [1,2,3,4,5] in ruby
give ruby version of this python code: `lambda s:len(s)==len({*s.lower()}-{*str(56**7)})` in ruby
give struct version: `class series def initialize(series) = @series = series def slices(n) raise argumenterror if n > @series.length @series.chars.each_cons(n).map(&:join) end end` in ruby
give the regex version (such as def isogram?(w) = p !w.match(/(.)(?:\1|-|\d)/i) for ` def isogram?(词) = 词.downcase.scan(/\w/) == 词.downcase.scan(/\w/).uniq` in ruby
given a string (that is also capitalized) input to a function, how to test whether it includes letters 'a', 'g', 't', and 'c'? in ruby
given a string of digits, output all the contiguous substrings of length n in that string in the order that they appear. in ruby
given a string representing a matrix of numbers, return the rows and columns of that matrix. in ruby
here sum all fibonacci terms that are even: `def fibona(n) return n if n < 2 fib_sequence = [1, 1] (1...n).each do |_| fib_sequence << fib_sequence[-1] + fib_sequence[-2] end fib_sequence end` in ruby
hg in ruby
how do i add these two element-wise so the result is another 3-element array? [*1..3] + [*4..6] in ruby
how do i collect the letters only from "\"five quacking zephyrs jolt my wax bed.\"" without using .downcase method? in ruby
how do i convert this to an array of strings: `[0, [0, 1], {foo: 0}] * ', '` in ruby
how do i count each word in "wa ta're ba 100" such that (two words contracted like `ta're` are counted as one) and numbers are also counted as words? in ruby
how do i count how often each word occurs in "wa ta're wa ba 100 ba ba 100 200" such that (two words contracted like `ta're` are counted as one) and numbers are also counted as words? in ruby
how do i fix this ` attr_accessor :age, :member alias_method :initialize, :age=` such that initilizer method has member set to false? in ruby
how do i select only the letters in "\"five quacking zephyrs jolt my wax bed.\""? in ruby
how to 3 × 1 10 100 such that the result is 3 30 300? in ruby
how to calculate prime numebrs in ruby
how to change `cols = %w(black, brown, red)` to this: `cols = { "black" => '0', "brown" => '1', "red" => '2'}` in ruby
how to change method name with alias? in ruby
how to check if a number is in an array? like `5 in [1, 3, 5]`? in ruby
how to check if an array is empty? in ruby
how to compute the sum in [{:l=>8},{:s=>7, :m=>2}]? in ruby
how to compute the total found in this array? [{:s=>3, :m=>7, :l=>8},{:s=>7, :m=>2}] in ruby
how to create a 2 x 3 matrix in apl? in ruby
how to create this: 'abcdefghijklmnopqrstuvwxyz' using a shortcut code in ruby
how to do a one-liner c# function? in ruby
how to extract only the words from this string: "[\"\\\"blink\\\",\", \"\\\"freakonomics\\\",\", \"\\\"outliers\\\"\"]" in ruby
how to find multiples of two numbers not exceeding some n? in ruby
how to fix `print ([2, 4, 6].all?(:&even?)` in ruby
how to fix? `[1, 10, 100].map(&:prod * 3)` in ruby
how to iterate over "thequickbrownfoxjumpsoverthelazydog" to check if it represents every letter of the english alphabet? in ruby
how to iterate over each elements of "the quick brown fox jumps over the lazy dog" to check if they exist in [*'a'..'z']? ignore white space in ruby
how to produce the equivalent apl's `10×⍳2+5` ? in ruby
how to return the total value of all the hash values of three hashes, each of which is an element of an array using map or some shorter code? in ruby
how to return the total value, as an integer, of all the hash values of three hashes, each of which is an element of an array? in ruby
how to salt a password in ruby
how to select first two elements of an array and loop over them? in ruby
how to sum [{ a: 5, b: 10, c: 15 }, {}, {q: 67}] such the i don't get the "undefined method `values' for nil:nilclass" error in ruby
how to sum hash values in an array of five hashes? in ruby
how to sum the values in [{ a: 5, b: 10, c: 15 }, {}, { q: 67 }] in ruby
how to sum this if the hash is inside an array? [{ a: 5, b: 10, c: 15 }] in ruby
how to sum values found in a hash? in ruby
how to use [1..4] to generate an array in ruby
how to write a program that getting this str where str = "\"five quacking zephyrs jolt my wax bed.\"", confirms that it is a pangram? in ruby
i did not understand this when i was reading ruby docs: "::[]: returns a new array populated with given objects." in ruby
i have an array [1,2,3]. and my input to function arg is n. if n is either 1 or 2 or 3, do sth. if n is a number not in that array, do sth else. give me the code. in ruby
i have an array with 3 elements, each is a hash. how to print the third hash? in ruby
if a file.txt is in the same directory, can i use load to load it into my function that should read the contents to screen? how to do it with 'load file.rb' method? in ruby
if a file.txt is in the same directory, can i use load to load it into my function that should read the contents to screen? how? in ruby
if a string begins with a bullet or dash, remove it. in ruby
if example in ruby
in julia, given a year, report if it is a leap year. in ruby
in ocaml, how do i find the max value of a list of ints? in ruby
in ocaml, i ran this caml program: `x + 2 where x = 34` why did it fail? in ruby
in the previous answer, is initialize an instance method? in ruby
in the regex /(.).*\1|\d/i in ruby, how to also check for hyphens and white-space in ruby
initialize connection with metasploit rpc in ruby
insert a string into another string at a specific index in ruby
insert an element into an array at a specific index in ruby
is there a ruby's lst.max in ocaml in ruby
is there a shortcut for `class isogram def self.isogram? #code here end end in ruby
is there a to_array methd? in ruby
is there one-liner shortcut for `class << self def isogram? # code here end end` in ruby
is there one-liner shortcut for `class << self def isogram? # code here end end` ? make sure to include class in ruby
is there one-liner shortcut for `class << self def isogram? # code here end end` ? make sure to include class in ruby in ruby
is this best way to learn a new programming language through a cookbook? in ruby
is this wrong? ` def ticket_price @age => 60 ? 10 : 15 end` in ruby
iterate an array of strings with index in ruby
iterate over a list in ruby
iterate over an array of strings with index using the map function in ruby
iterate through json variables in ruby
join an array of characters into a string in ruby
join an array of substrings into a string in ruby
join two strings in ruby
left pad with space in ruby
make a get request in ruby
make a http delete request in ruby
make a http head request in ruby
make a http post request in ruby
make a http request with a custom body in ruby
make a http request with a custom body as binary in ruby
make a http request with a custom body as binary and return a binary response in ruby
make a http request with a custom body as form data in ruby
make a http request with a custom body as form url encoded in ruby
make a http request with a custom body as html in ruby
make a http request with a custom body as json in ruby
make a http request with a custom body as json and return a json response in ruby
make a http request with a custom body as multipart form data in ruby
make a http request with a custom body as text in ruby
make a http request with a custom method in ruby
make a http request with url parameters in ruby
make it even shorter: `class year def self.leap?(y) = y % 400 == 0 || (y % 100 != 0 && y % 4 == 0) end` in ruby
make me a website in ruby
move a csv file in ruby
move a directory in ruby
move a file in ruby
move a json file in ruby
multiply two numbers in ruby
oauth in ruby
on which types of things can i run the ruby for loop n.times do block? in ruby
one last example. write a function that gives the max value of digits in a number: if the number is 689 for instance, it should return 9. in ruby
one-liner function to check if a year is a leap year in ruby
open a new meterpreter session using the exchange_proxyshell_rce exploit in ruby
override a getter on a subclass in ruby
override a method on a subclass in ruby
override a private property on a subclass in ruby
override a private static property on a subclass in ruby
override a property on a subclass in ruby
override a setter on a subclass in ruby
override a static method on a subclass in ruby
override a static property on a subclass in ruby
parse authorization headers in ruby
parse jwt tokens in ruby
prepend a string to the beginning of another string in ruby
print "welcome back!" in ruby
prompt user for their full name, separated by space. then greet them with their full name: 'salam, firstname lastname'. in ruby
read a csv file in ruby
read a file in ruby
read a json file in ruby
remove a character from a string in ruby
remove a character from a string at a specific index in ruby
remove a key-value pair from a map in ruby
remove a node from the beginning of a linked list in ruby
remove a node from the end of a linked list in ruby
remove a node from the middle of a linked list in ruby
remove a substring from a string in ruby
remove a substring from a string at a specific index in ruby
remove all white space in ""the quick brown fox jumps over the lazy dog"" in ruby
remove an element from an array at a specific index in ruby
remove an element from the beginning of an array in ruby
remove an element from the end of an array in ruby
remove an element from the middle of an array in ruby
remove any leading white space (tabs, spaces, and new lines) in ruby
rename a csv file in ruby
rename a directory in ruby
rename a file in ruby
rename a json file in ruby
replace a character in a string in ruby
replace a substring in a string in ruby
return a binary response from a http server in ruby
return a html response from a http server in ruby
return a json response from a http server in ruby
return a json response from a http server with a specific status code in ruby
return a text response from a http server in ruby
reverse an array in ruby
round a number to the nearest hundredth in ruby
round a number to the nearest integer in ruby
round a number to the nearest ten thousandth in ruby
round a number to the nearest tenth in ruby
round a number to the nearest thousandth in ruby
select from an array whose elements are hashes in ruby
select the first two elements of an array, loop over them such that their index numbers become digits (like 01) in ruby
send a binary json message to a tcp server in ruby
send a binary json message to a udp server in ruby
send a binary message to a tcp server in ruby
send a binary message to a udp server in ruby
send a json message to a tcp server in ruby
send a json message to a udp server in ruby
send a message to a tcp server in ruby
send a message to a udp server in ruby
send a post request with multipart/form-data in ruby
several ways to swap elements in [1, 2]? in ruby
shorten: `def con(n) return 'pg' if (n % 105).zero? return 'plg' if (n % 15).zero? return n.to_s end` in ruby
shorter way to do: ` cols = {black:0, brown:1, red:2} def value(arr) = (cols[arr[0].to_sym].to_s + cols[arr[1].to_sym].to_s).to_i end` ? in ruby
shorter way to do: `(cols[arr[0].to_sym].to_s + cols[arr[1].to_sym].to_s).to_i` ? in ruby
shortest latest way to write classes in ruby? in ruby
shortest possible isogram checker that can also scan for hyphens, dahses and white space? in ruby
show me an example where a class method is used and necessary where instance methods wouldn't do in ruby
shuffle a string in ruby
shuffle an array in ruby
single-line method in ruby
sort an array in ruby
split a map into two maps in ruby
split a string into an array of characters in ruby
split a string into an array of substrings in ruby
split a string into an array of words in ruby
split a string into two strings in ruby
subscribe to webhook in ruby
subtract two numbers in ruby
take the absolute value of a number in ruby
take the arccosine of a number in ruby
take the arcsine of a number in ruby
take the arctangent of a number in ruby
take the ceiling of a number in ruby
take the cosecant of a number in ruby
take the cosine of a number in ruby
take the cotangent of a number in ruby
take the derivative of a function in ruby
take the floor of a number in ruby
take the integral of a function in ruby
take the secant of a number in ruby
take the sine of a number in ruby
take the tangent of a number in ruby
teach me array#each what it does and how? in ruby
teach me how to use `each_cons` in ruby
this is a ruby isogram checker: `p !/(.).*\1|\d/i` where do i put the word that needs to be checked? in ruby
turn into one-liner: `def con(n) return 'pg' if (n % 105).zero? return 'plg' if (n % 15).zero? n.to_s end` in ruby
vending machine in ruby
what am i doing wrong here? `https://exercism.org/tracks/ruby/exercises/moviegoer` in ruby
what am i doing wrong? `class twelvedays def self.song = p file.open('ruby/twelve-days/song.txt', "r").read end` in ruby
what does "iterating over consecutive elements" mean and show example in ruby
what does (&:even?) replace? can i use (&:) everywhere as iteraror? in ruby
what does it mean `[nil, true, 99].all? ` in ruby
what does s+ in str.gsub(/\s+/ mean in ruby
what is a class method? in ruby
what is happening here? `def double_integer(i) i << 1 end` in ruby
what is ostruct in ruby
what is this sml: `fun max xs = foldl int.max (hd xs) (tl xs)` in ocaml and in ruby
what is wrong here? " def cheap = @items.map { |itm| itm[:price].select {|prod| prod if prod < 30}}" in ruby
what is wrong here? ` def claim_free_popcorn! @member == true ? '🍿' : notmovieclubmembererror.new("not a member") end` in ruby
what is wrong? `def taker(n) mul = [] (1..n).each do |i| mul << i if (i % 15).zero? end return mul.sum end puts taker(10)` in ruby
what is wrong? `print([1, 3, 6, 9 ].find { |e| e < 9 })` in ruby
what is wrong? `series = struct.new(:strng) { def slices(n) n > @strng.length ? argumenterror : @strng.each_char.each_cons(n).map(&:join) end }` in ruby
what to do in order to get ["0", "[0, 1], "{foo: 0}"] in ruby
what's wrong? ` def solution(n) multiples = [] (1..n).each do |x| if x % 15 == 0 multiples << x end if x < 0 return 0 end return multiples.sum end` in ruby
what's wrong? ` module resistorcolorduo cols = %w(black brown red orange yellow green blue violet grey white).map.with_index.to_h def self.value(input) = input.first(2).sum('', &cols).to_i end` in ruby
when i do `%w[0, [0, 1], {foo: 0}]` i get ["0,", "[0,", "1],", "{foo:", "0}"]. what to do in order to get ["0", "[0, "1], "{foo: 0}"] in ruby
why can't `/(.).*\1|\d|[-\s]/i` detect that "thumbscrew-japingly" is an isogram? in ruby
why is there a need to have class methods? in ruby
write a 2x3 integer-based matrix in ruby, and then show how to reverse it so that 1 2 3 in row 1, becomes 3 2 1, and 4 5 6 in row two becomes 6 5 4 in ruby
write a method to return true if the input string equals 'cool' otherwise return false in ruby
write a program that detects if a sentence is a pangram in ruby
write conditional in ruby
write me this program: "if they printed a brown band (value 1) followed by a green band (value 5), it would translate to the number 15." in ruby
write this program such that the 10th fibonacci term is 89: `def fibo(n) return n if n < 2 && n > 0 a, b = 0, 1 for k in 1..n a, b = b, a + b end a end` in ruby
write to a csv file in ruby
write to a file in ruby
write to a json file in ruby
gistlib
by LogSnag