Questions tagged [splat]

The `*` operator as used in Ruby. So called because it looks like an insect that's splatted on a windscreen.

The * operator as used in Ruby. So called because it looks like an insect that's splatted on a windscreen.

166 questions
0
votes
1 answer

zip_longest on Array with lists of the same length. Understanding

I have an Array which contains a few lists all the same length. All those lists need to be written in a .csv-file. Using a piece of code i have found it works pretty well. Here the code: ag=[[1,2,3],[4,5,6],[7,8,9],[10,11,12]] export_data =…
McMo
  • 151
  • 1
  • 9
0
votes
1 answer

Python string interpolation with splat operator?

I have a large (~10 elements) list of integers that I wish to interpolate into a string. This seems like an ideal use case for the splat operator, so I'd like to be able to do something like this: """[latex]$\begin{bmatrix} %d & %d \\ %d &…
pseudosudo
  • 6,270
  • 9
  • 40
  • 53
0
votes
2 answers

Most efficient way to texture splat opengl?

I have to combine up to 17 textures and then render it to a quad (well, 2 triangles) using openGL. I have to render a great deal of these quads - perhaps 500. I was wondering what the fastest/best method to doing so: A. render in many passes B.…
Pubby
  • 51,882
  • 13
  • 139
  • 180
0
votes
0 answers

Python splat operator error

I have a map iterator gmm and I'm sending it to a function called fisher_vector but I receive the following error: TypeError: fisher_vector() missing 3 required positional arguments: 'means', 'covs', and 'w' I call the function in this line: return…
Daniel Zapata
  • 812
  • 3
  • 9
  • 31
0
votes
2 answers

Splat parameters behave differently for attribute writers compared to regular method

I have the following two methods, which I believe should have the same behaviour disregarding their names: def a=(*params) params end def b(*params) params end But when in fact I use them: a=(1) # => 1 b(1) # => [1] (a=1) == b(1) # =>…
thisismydesign
  • 21,553
  • 9
  • 123
  • 126
0
votes
1 answer

Rails 3 - Splat attr_accessible with Active Record

I'm making typedoptions dynamic by moving them to a new model, as you can see before I was using a constant to make the columns t_a, t_b, t_c accessible with *TYPED_DATA, but now that the model has been migrated, i can't do it anymore. Is there a…
raul782
  • 479
  • 1
  • 5
  • 15
0
votes
2 answers

two level splatter TCL

If I have a procedure or a command in TCL, with variable number of arguments, one can use, if a list's elements are as an input, the "splatter" operator, for example: set a [list "ko" ] set m [ list "ok" "bang" ] lappend a {*}$m But, what if I want…
user1134991
  • 3,003
  • 2
  • 25
  • 35
0
votes
1 answer

Ruby - extending method with super using splat

In "Comprehensive Ruby programming course" e-book I have a case when the child class method extends parents method. I am not completely aware how it works: class Parent def initialize(foo:, bar:) @foo = foo @bar = bar end end class Child…
Julius Dzidzevičius
  • 10,775
  • 11
  • 36
  • 81
0
votes
3 answers

Ruby splat operator: Array(1..10).equal? [*Array(1..10)] => false?

I was looking at: hash_1 = Hash[*[Array("a".."j"), Array(1..10)].transpose.flatten] So I thought, the return with or without the splat, "*", looks the same - so why hash_1 = Hash[[Array("a".."j"), Array(1..10)].transpose.flatten] returns {} …
ayuspark
  • 21
  • 2
0
votes
1 answer

Using a splat to catch errors is not working

I have a lot of errors that I need to catch, so I put them all into two arrays and made a constant to hold them, however, when I run the program I receive the…
0
votes
1 answer

ruby splat operator compilation error in eclipse but runs fine on command line

I have the following ruby script ruby_test.rb in eclipse (DLTK/RUBY), which throws a compilation error and I am not able to run in eclipse. This makes sense since *arr should be the last parameter. But when I run it on command line (ruby…
North
  • 21
  • 4
0
votes
1 answer

How use an array of strings to create multiple ActiveRecord objects at once?

I have an array of strings: days = ["Monday", "Tuesday", "Wednesday"] I'd like to create a Day in the database named after each of these: days.each do |day| Day.create(name: day) end This isn't so cute, however. In the past, I have been able to…
Dylan Richards
  • 796
  • 3
  • 9
  • 26
0
votes
1 answer

Passing array to one of named parameters in script block?

I am trying to figure out a way to pass an array to a named parameter in a separate script. However, I could not find any solution. Test2.ps1: param( [int]$a, [int]$b, [int]$c, [string[]]$d ) write-host "`$a = $a" write-host "`$b =…
0
votes
1 answer

In Ruby: I'm giving a method an argument somehow when calling it, but don't know where. I think it has something to do with block bindings?

Apologies for not knowing how to state this question better. I was noticing how the block syntax of {} binds to the object immediately to the left, and then noticed the do/end binds to the object that starts the line. In the process, I noticed…
Tony DiNitto
  • 1,244
  • 1
  • 16
  • 28
0
votes
1 answer

Method: Loop Through Arguments with Defaults

I am building a Ruby object that has defaults for arguments in its initialize method: attr_accessor :one, :two, :three def initialize(one: nil, two: nil, three: nil) @one = one @two = two @three = three end As you can see, this isn't very…
RedBassett
  • 3,469
  • 3
  • 32
  • 56