Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

QueryStruct is alive.

  • Loading branch information...
commit 0b05b03b433f3559444c1529800d2266a1a5fd1b 1 parent 9139364
Rein Henrichs authored September 01, 2010
10  README.rdoc
Source Rendered
... ...
@@ -1,9 +1,15 @@
1 1
 = qstruct
2 2
 
3  
-Description goes here.
  3
+An OpenStruct that provides query methods for its members.
  4
+
  5
+== Example:
  6
+    require 'qstruct'
  7
+    options = QueryStruct.new(:debug => true, :trace => false)
  8
+    options.debug? # => true
  9
+    options.trace? # => false
4 10
 
5 11
 == Note on Patches/Pull Requests
6  
- 
  12
+
7 13
 * Fork the project.
8 14
 * Make your feature addition or bug fix.
9 15
 * Add tests for it. This is important so I don't break it in a
9  lib/qstruct.rb
... ...
@@ -0,0 +1,9 @@
  1
+require 'ostruct'
  2
+class QueryStruct < OpenStruct
  3
+  # Add query methods to struct members.
  4
+  def new_ostruct_member(name)
  5
+    super
  6
+    meta = class << self; self end
  7
+    meta.send(:alias_method, "#{name}?", name)
  8
+  end
  9
+end
7  test/test_qstruct.rb
... ...
@@ -1,7 +1,8 @@
1 1
 require 'helper'
2 2
 
3 3
 class TestQstruct < MiniTest::Unit::TestCase
4  
-  def test_something_for_real
5  
-    flunk "hey buddy, you should probably rename this file and start testing for real"
  4
+  def test_query_alias
  5
+    qstruct = QueryStruct.new(:query => true)
  6
+    assert qstruct.query?
6 7
   end
7  
-end
  8
+end

0 notes on commit 0b05b03

Please sign in to comment.
Something went wrong with that request. Please try again.