Showing posts with label ruby. Show all posts
Showing posts with label ruby. Show all posts

Friday, 16 November 2012

RLint 1.0

Hi folks, Today, I'll show to you the progress from my little tool called RLint. E.G, I have a test code and I need check if it's following my coding standards. Setting up this configuration (Today hardcoded, but in release version the configuration will be through config file): Tabulation - Tabs, size 4 Class Name - Camel case Column Delimiter - 80 If Bracket - No Source code - teste.rb
class AV
end

class AudioVideo
  def method_column_delimiter_80
    "String really loooooooooooooooooooooooooooooooooooooooooooooooonnnnnnnnnnggggggggggggggggggggggggggg"
  end

  def method_no_bracket
    if(abc)

    end

    if abc

    end
  end
end

When running rlint.rb, I get this output (Alright, the error messages are really useless or confused, however, I know it needs improvement):
rodrigo@:~/RubyProjects/rlint$ ruby rlint.rb teste.rb
Tabulation report:
Correct: 5
Error: 13

You need review this lines:
Detected a indentation mistake.
> teste.rb - 6:   def method_foo
Detected a whitespace indentation.
> teste.rb - 6:   def method_foo
Detected a whitespace indentation.
> teste.rb - 7:     "String really loooooooooooooooooooooooooooooooooooooooooooooooonnnnnnnnnnggggggggggggggggggggggggggg"
Detected a indentation mistake.
> teste.rb - 8:   end
Detected a whitespace indentation.
> teste.rb - 8:   end
Detected a indentation mistake.
> teste.rb - 10:   def method_xxx
Detected a whitespace indentation.
> teste.rb - 10:   def method_xxx
Detected a whitespace indentation.
> teste.rb - 11:     if(abc)
Detected a whitespace indentation.
> teste.rb - 13:     end
Detected a whitespace indentation.
> teste.rb - 15:     if abc
Detected a whitespace indentation.
> teste.rb - 17:     end
Detected a indentation mistake.
> teste.rb - 18:   end
Detected a whitespace indentation.
> teste.rb - 18:   end


Class/Module name report:
Correct: 1
Error: 1

You need review this lines:
Detected a class name mistake. Possible Snake Case
> teste.rb - 2: class AV


If parenthesis report:
Correct: 1
Error: 1

You need review this lines:
Detected a configuration mismatch for bracket usage.
> teste.rb - 11:     if(abc)


Column Delimiter report:
Correct: 19
Error: 1

You need review this lines:
Detected a word across the delimiter.
> teste.rb - 7:     "String really loooooooooooooooooooooooooooooooooooooooooooooooonnnnnnnnnnggggggggggggggggggggggggggg"
I'm think so it's really delighted, if you have a program that help check your coding standards.

Tuesday, 30 October 2012

Adding object dinamically to a class.

Ruby's a great programming language everybody know. The breakthrough in Ruby is adding objects dynamically in a class, it's really amazing. Why? It's possible to create a simple interface with high complexity. For example, it's really viable create a car only adding parts in the object. How did you do this? Using 'self.class.send(:define_method, name, &block)'. This code will add a instance method (name) and code method (&block). Actually, if you pass a object via &block, your new method will behave like a object and your master class will be clean and it don't need implement nothing. I'm not quite sure about design pattern name, although I like this. Example:
class Car 
 def add_wheel(wheel)
  add_object("wheel"){wheel}
 end 
 
 def add_part(name, obj)
  add_object(name){obj}
 end 
 
 private
 
 def add_object(name, &block)
  self.class.send(:define_method, name, &block)
 end   
end

class Wheel
 def initialize(size)
  @size = size
 end 
 
 def size
  puts "Wheel size #{@size}"
 end 
end 

class CarPaint
 def initialize(colour)
  @colour = colour
 end 
 
 def is_metallic_color?
  true
 end
 
 def colour
  puts "Colour #{@colour}"
 end
end 

my_car = Car.new
my_car.add_wheel(Wheel.new(17))

my_car.wheel.size
my_car.add_part("colour", CarPaint.new("red"))

puts my_car.colour.is_metallic_color?
my_car.colour.colour

Wednesday, 14 July 2010

RHash 0.0.3 Released

Portuguese:
- Alguns bugs simples foram corrigidos
- Documentação dos métodos.

TODO:
- Implementar Unit Test
- Implementar Teste de Desempenho
- Organizar o código

English:
- Fix: Minor bugs.
- Documentation.

TODO:
- Develop: Unit Test
- Develop: Performance Test
- Organization

Download(via http): http://rubygems.org/gems/rhash
Download(via rubygems): (sudo) gem install rhash

Tuesday, 13 July 2010

RHash 0.0.1: Released

TODO:
- Create: RDOC
- Create: Unit Tests

------
OFF:
Don't have any bugs... [ As far as I know. :) ]