Questions tagged [ruby-parser]
11 questions
3
votes
1 answer
create a rubocop cop that triggers when method is invoked without a block
I'm trying to develop a new cop (based on these guidelines) and am banging my head trying to get the correct node pattern.
I want the cop to register an offense when X.some_method is called without providing a block.
i.e X.some_method is an…

J. Ed
- 6,692
- 4
- 39
- 55
3
votes
2 answers
Why do I have a trailing column when reading a CSV file?
I have a CSV file whith the following structure:
"customer_id";"customer_name";"quantity";
"id1234";"Henry";"15";
Parsing with Ruby's standard CSV lib:
csv_data = CSV.read(pathtofile,{
:headers => :first_row,
:col_sep => ";",
…

Gilles
- 167
- 8
1
vote
1 answer
Why doen't this send pattern match?
I have written a custom rubocop cop, the excerpts are like this:
def_node_matcher :is_foo_bar?, <<-PATTERN
(send (const nil :Foo) :bar)
PATTERN
def on_send(node)
puts "Match" if is_foo_bar?(node)
end
I'm trying the cop on the following…

sudoremo
- 2,274
- 2
- 22
- 39
1
vote
1 answer
parsing vagrant file inside java
I need to parse the configurations defined in a Vagrantfile written in Ruby and use the settings elsewhere in my java code. Tried exploring jRubyParser but din't come across any documentation that defines it's use.
Cloned the Vagrant repo locally,…

akskap
- 803
- 6
- 12
1
vote
1 answer
Usage of ruby_parser, AST in prior 1.8.7 and S-expression in ruby?
Recently I am converting the ror project that uses ParseTree in ruby 1.8.7 to ruby 1.9.3
Figured out that ParseTree cannot work with 1.9.3, Searched for it in bunch of googlers, still stuck with some code-migration
Found various alternative like…

millisami
- 9,931
- 15
- 70
- 112
1
vote
2 answers
Equivalence between ifs and forms of case statements in Ruby
Using the ruby_parser and Ruby2Ruby gems, I'm writing code that keeps track of what conditions have been evaluated and what their results and parameters were. In order to keep this as simple as possible, I sometimes rewrite the AST a bit. Of course,…

Confusion
- 16,256
- 8
- 46
- 71
0
votes
0 answers
What is the solution of this error whenever i run this function it gives me output but also gives me list of that error?
time = Time.parse(@year)
puts "#{time.strftime("%B_%Y")}"
file_path = file_access
CSV.foreach(file_path[0], headers: true, header_converters: :symbol, skip_blanks: true) do|row|
day = Time.parse(get_date(row)) #Error line
max =…

Rabab Zahra
- 3
- 2
0
votes
1 answer
How can I parse multiple lines using ruby_parser?
I'm trying to use ruby_parser to parse some multi-lined Ruby code in a file.
Let's say I want to parse the following code:
def foo
2 + 2
end
When I do the following I get an error:
RubyParser.new.parse("def foo")
#=> Racc::ParseError: (string):1…

garythegoat
- 1,517
- 1
- 12
- 25
0
votes
1 answer
Running Metrical with 1.9 Hash Syntax
I want to use Metrical with my brand-new Rails project using Ruby 1.9 hash syntax doing things like
before_filter :guest_user, only: [:new, :create]
before_filter :correct_user, only: :destroy
and I get this…

bento
- 2,079
- 1
- 16
- 13
-1
votes
2 answers
Ruby - Parse array of json files
I have an array of json files.this is the sample of single json file,
{
"job": [
"admin",
"developer"
],
"name": "dave"
}
i need to get the "name" value if admin exist in "job". Need to do the same for other json files in the…

Vishnu Prassad
- 333
- 1
- 3
- 12
-4
votes
1 answer
Syntax error, unexpected ':', expecting ')' - Rails 2.1.0
Getting a syntax error when running rake tasks:
bundle exec rake test:read_message
ruby -v
2.1.0
/ruby/gems/2.1.0/gems/spring-1.7.1/lib/spring/client/run.rb:76: syntax error, unexpected ':', expecting ')' (SyntaxError)
..._env,…

Bahubali
- 1
- 2