Skip to main content
The 2024 Developer Survey results are live! See the results

All Questions

Tagged with
2 votes
0 answers
162 views

How to call "unpack" on a string in ruby C-api?

I am trying to use the ruby C-api to call unpack on a ruby string. Here is my current code: #include "ruby.h" #include <stdio.h> #include <unistd.h> VALUE dangerous_func(...
Some nerd who does not have a 's user avatar
-1 votes
1 answer
63 views

In Ruby, how do you set the value for only one specific method argument, while just using the default values for other arguments?

Th parent_class instance variable for this class has a default value "String". I want to make an instance that has parent_class = "None". My super_string1 instance definition works ...
Brijesh's user avatar
  • 27
-1 votes
2 answers
745 views

Ruby: ArgumentError (wrong number of arguments (given 1, expected 0)) [closed]

I'm clearly fundamentally not understanding how to pass arguments and call methods in Rails. I'm trying to make a test call to stripe with dummy information and I'm getting the subject error when I ...
John Gerard's user avatar
0 votes
1 answer
31 views

Cucumber: variable used to complete a method in ruby

Is there an elegant way to use the variable var_name in the method below - so whichever name used as a first string in the step will be reflected at the end of the var? Then('the {string} variable in ...
Kamilo's user avatar
  • 17
0 votes
2 answers
52 views

How to use integer methods using `method`, not their infix form, in Ruby

I am looking to programmatically apply a typically infixed operation (eg: +, -, *, /) on two integers, where the operation is specified via a string. I have had success accessing the method itself ...
MolarFox's user avatar
3 votes
1 answer
206 views

Does Crystal have attribute accessor methods like in Ruby?

Does the Crystal programming language have an equivalent to Ruby's attribute accessor methods? More specifically, does Crystal have equivalents to the following? attr_accessor attr_reader attr_writer ...
Jacob M. Barnard's user avatar
1 vote
1 answer
45 views

How do I get a recursive method to take a, non argument, block and run it on each recurrent call?

I'm trying to write a recursive binary tree depth first, pre-order, traversal method and have it also work when it's passed a block. But I'm struggling to work out how to get it to use the passed ...
jbk's user avatar
  • 2,092
2 votes
1 answer
63 views

What is it that this #divmod method is doing to output this result?

I have two arrays: a = [7, 1, 65, 4, 13, 97] b = [] and I'm trying to append the #divmod return values of each of a's elements into b, via the following code: b << a.map(&4.method(:divmod)) ...
jbk's user avatar
  • 2,092
-1 votes
1 answer
112 views

Ruby: Creating a class method that all classes can use [duplicate]

I am trying to create a method that can be called by any class, similar to how .is_a? can be called by any class. How can one go about this? I have tried using alias_method and Class.send(method) to ...
RomanRhino's user avatar
0 votes
1 answer
53 views

Defining methods with menu in Ruby

I have this code just for demonstration in favor for my question. How can I sort these three commands into three different methods? And also am I thinking right? I already wrote the menu, and I'm ...
user avatar
1 vote
1 answer
82 views

How to modify array using multiple conditions in Ruby

Im started to study Ruby today and i don't understand yet how to modify a array with multiple conditions, I had search about this and reading documentantion but just found with one condition. I tried ...
Clever Júnior's user avatar
0 votes
1 answer
74 views

Ruby: how to make class return true?

I'm a ruby beginner, and I'm not sure how to make test return 'true' class Hash def in(*) end end # cannot alter below this line def test { a: 1 }.in(:a) == 1 end puts "test: #{test}"...
James Nine's user avatar
  • 2,598
1 vote
1 answer
34 views

Ruby how to use method parameter embedded in call to another method other than just puts

In Ruby I want to use an input parameter for REST verb (like 'Post') in a call to Net::HTTP new but I can't work out how to embed the parameter in the statement. I have the param called restVerb which ...
Andrew Walker's user avatar
0 votes
2 answers
138 views

How to define setter methods for all keys in a hash dynamically

I am writing a class which has a hash data member. The hash is initialized to have a set of keys with default values in the constructor. How do I then generate setter methods corresponding to all the ...
PKP's user avatar
  • 17
0 votes
3 answers
120 views

Ruby Anagrams puzzle

i a m a begginner in ruby please i need directions in how to get the program to return a list containing "inlets" Question: Given a word and a list of possible anagrams, select the correct ...
Precious's user avatar

15 30 50 per page
1
2 3 4 5
96